Code Room
Vibe codingHard
Question
An AI generated this C++ code to copy a variable-length name field out of a received packet into a fixed struct. Code review missed it; a fuzzer found a heap overflow. Identify the memory bug, the packet that triggers it, and the safe rewrite.
struct Peer { char name[32]; uint16_t port; }; void load_peer(Peer *p, const uint8_t *pkt) { uint8_t name_len = pkt[0]; // attacker-controlled length memcpy(p->name, pkt + 1, name_len); p->name[name_len] = '\0'; p->port = (pkt[1 + name_len] << 8) | pkt[2 + name_len];}What a strong answer looks like
Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.