gcc -fanalyzer and clang --analyze both reported findings that trace back to scr_die() looking like an ordinary call: a possible NULL passphrase dereference in strip_passphrase, and a double free of the temp key path (the analyzer believed the conversion-failure branch returned and handed the freed pointer back to the caller). exit() never returns, so say so with SCR_NORETURN. Both analyzers are silent now; the suite is unchanged at 31/31.
This commit is contained in:
1 parent
1202fe0090
commit
2c381cbe75
2 files changed
+15
-1
No files matched your search
@@ -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 `<stdio.h>` is a hard error under
|
||||
`-std=c99 -Wpedantic`.
|
||||
|
||||
|
||||
+11
-1
@@ -3,6 +3,16 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* 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);
|
||||
|
||||
Reference in new issue
Block a user