diff --git a/AGENTS.md b/AGENTS.md index 2297b29..53155d7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,6 +77,10 @@ you pass; do not remove that `override`. a field that merely contains a type name is skipped unless its base64 decodes to that same type. A substring search accepts `# disabled: ssh-ed25519 ...` and breaks on `command="echo ssh-rsa hi"`. +* `scr_die()` is declared `SCR_NORETURN`. Without the attribute both + `gcc -fanalyzer` and `clang --analyze` treat the code after a fatal call as + reachable and report a NULL dereference and a double free that cannot happen. + Keep it when touching the error paths. * Every `.c` includes its own headers; missing `` is a hard error under `-std=c99 -Wpedantic`. diff --git a/src/sshcrypt.h b/src/sshcrypt.h index 363b2f3..97b6277 100644 --- a/src/sshcrypt.h +++ b/src/sshcrypt.h @@ -3,6 +3,16 @@ #include +/* C99 has no _Noreturn; both compilers we target do have the attribute. It + * matters: without it a static analyzer cannot tell that an error path ends, + * and it reads the cleanup after scr_die() as a fall-through (it reported a + * double free of the temp path for exactly that reason). */ +#if defined(__GNUC__) || defined(__clang__) +#define SCR_NORETURN __attribute__((__noreturn__)) +#else +#define SCR_NORETURN +#endif + #define SCR_VERSION 1 #define SCR_VERSION_STR "0.1.1" #define SCR_SUITE_X25519 1 @@ -27,7 +37,7 @@ struct buf { }; /* util.c */ -void scr_die(int code, const char *fmt, ...); +void scr_die(int code, const char *fmt, ...) SCR_NORETURN; void *scr_xmalloc(size_t n); void *scr_xrealloc(void *p, size_t n); char *scr_xstrdup(const char *s);