#2919·firmware

Array overflow and memory leak loading a custom pwnagotchi faces/names file

Author: TheOnionJrCreated Sep 21, 2026Updated Sep 21, 2026

loadFacesAndNames() fills two fixed 30-entry global arrays from a user-loaded .txt file with no bound check on the write index. A faces= line with more than 30 entries overflows straight into the adjacent names[] array (confirmed under AddressSanitizer: entry 31 lands exactly on names[0]). Separately, reusing the same key twice in one file leaks the first set of allocations.

Location: src/modules/pwnagotchi/spam.cpp, lines 28-29 and 324-354

cpp
const char *faces[30];
const char *names[30];
...
num_faces = 0;
while (end != -1) {
    faces[num_faces++] = strdup(faces_line.substring(start, end).c_str());  // no bound check

Suggested fix: free existing entries before resetting the counter, and bound the loop:

cpp
for (int i = 0; i < num_faces; i++) free((void *)faces[i]);
num_faces = 0;
while (end != -1 && num_faces < 30) { ... }

Same shape for names=.