fix: compare the coredump build SHA without reading past the array

app_elf_sha256 has no terminator (IDF 4.4 fills all 17 bytes), so strcmp
never matched the running build and %s printed whatever followed it.  Copy
it into a terminated buffer first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-12 18:29:59 +02:00
parent 2ee7af51ab
commit e1c76bc2af
2 changed files with 15 additions and 1 deletions

View file

@ -86,7 +86,11 @@ void setup() {
#endif
// The backtrace only decodes against the firmware.elf of the build that
// crashed, so say whether that is the one running now.
const char *crashedSha = (const char *)summary.app_elf_sha256;
// app_elf_sha256 isn't always terminated, so copy it before comparing or
// printing it.
char crashedSha[APP_ELF_SHA256_SZ];
static_assert(sizeof(crashedSha) <= sizeof(summary.app_elf_sha256), "copy would read past app_elf_sha256");
SETCHARPROP(crashedSha, (const char *)summary.app_elf_sha256, sizeof(crashedSha));
char runningSha[APP_ELF_SHA256_SZ] = {0};
getRunningElfSha(runningSha, sizeof(runningSha));
if(strcmp(crashedSha, runningSha) == 0)