Medium
Scrubbing a password buffer before returning
readPassword and checkHash are defined in another translation unit, and there is no LTO. Compiled at -O2, does the memset that scrubs password survive into the generated code?
main.cpp
#include <cstddef>
#include <cstring>
bool readPassword(char* buf, std::size_t n);
bool checkHash(const char* pw);
bool login() {
char password[64];
if (!readPassword(password, sizeof password)) return false;
bool ok = checkHash(password);
std::memset(password, 0, sizeof password); // scrub the secret
return ok;
}38 of 44 in Compilers