diff options
author | Colin Watson <cjwatson@debian.org> | 2022-01-02 03:12:28 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2022-01-02 03:19:50 +0000 |
commit | a22f140354c80a7c5c52c4a413f1c929e105a24c (patch) | |
tree | 4d688f931cdb61c5ee3e60d861cbc9a50ea6550c /lib | |
parent | 9f8d0ed464e884b10cd0ab2d1f5b341f0334519d (diff) |
Assert that some xasprintf calls return non-NULL
"gcc -fanalyzer" notices that xasprintf can return NULL in some
situations (string length > INT_MAX, invalid format string, or multibyte
conversion error), and that we weren't handling this in various cases
where we use the return value in contexts that require non-NULL values.
The situations seem obscure enough for simple asserts to be appropriate.
* lib/pathsearch.c (pathsearch): Assert that xasprintf returns non-NULL.
* lib/tempfile.c (create_tempdir): Likewise.
* lib/util.c (remove_directory): Likewise.
* libdb/db_lookup.c (make_multi_key): Likewise.
* libdb/db_store.c (make_content, dbstore): Likewise.
* src/check_mandirs.c (add_dir_entries, fix_permissions_tree): Likewise.
* src/compression.c (comp_file): Likewise.
* src/globbing.c (look_for_file): Likewise.
* src/man.c (main): Likewise.
* src/mandb.c (mandb, purge_catsubdirs): Likewise.
* src/manp.c (pathappend): Likewise.
* src/ult_src.c (find_include): Likewise.
* src/whatis.c (use_grep): Likewise.
* src/zsoelim.l (zsoelim_open_file): Likewise.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pathsearch.c | 2 | ||||
-rw-r--r-- | lib/tempfile.c | 2 | ||||
-rw-r--r-- | lib/util.c | 2 |
3 files changed, 6 insertions, 0 deletions
diff --git a/lib/pathsearch.c b/lib/pathsearch.c index 363b5ee6..76b21997 100644 --- a/lib/pathsearch.c +++ b/lib/pathsearch.c @@ -24,6 +24,7 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include <assert.h> #include <errno.h> #include <stdbool.h> #include <string.h> @@ -82,6 +83,7 @@ static bool pathsearch (const char *name, const mode_t bits) } filename = xasprintf ("%s/%s", element, name); + assert (filename); if (stat (filename, &st) == -1) { free (filename); continue; diff --git a/lib/tempfile.c b/lib/tempfile.c index 91ee0fb1..f1dfb688 100644 --- a/lib/tempfile.c +++ b/lib/tempfile.c @@ -24,6 +24,7 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -73,6 +74,7 @@ char *create_tempdir (const char *template) if (!dir) return NULL; created_dirname = xasprintf ("%s/%sXXXXXX", dir, template); + assert (created_dirname); if (!mkdtemp (created_dirname)) return NULL; return created_dirname; @@ -35,6 +35,7 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include <assert.h> #include <string.h> #include <stdlib.h> #include <stdio.h> @@ -164,6 +165,7 @@ int remove_directory (const char *directory, int recurse) if (STREQ (entry->d_name, ".") || STREQ (entry->d_name, "..")) continue; path = xasprintf ("%s/%s", directory, entry->d_name); + assert (path); if (stat (path, &st) == -1) { free (path); closedir (handle); |