Welcome to your interview.
The question is on your right: Audit C++ Memory Bugs in Messenger. Take a moment with it first.
Talk your thinking through with me if you like - when you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes). Discussion and graded submissions share your five interviewer interactions, so spend them well.
A Security Engineer on Meta’s product security team is reviewing a small C++ utility used in a Messenger backend component. The code parses user-controlled input and builds a response buffer. Your task is to identify one memory leak and one buffer overflow vulnerability, explain why each occurs, and propose secure fixes.
#include <cstring>
#include <iostream>
void processMessage(const char* input) {
char* session = new char[64];
char reply[16];
strcpy(session, "active-session");
if (strlen(input) < 32) {
strcpy(reply, input);
}
std::cout << session << ": " << reply << std::endl;
}
input is user-controlled.std::string, std::array, or RAII.A strong answer should precisely distinguish between stack and heap memory issues, explain the impact of unbounded copies, and show a fix that removes both vulnerabilities rather than patching symptoms.