man-db/SOURCES/man-db-2.7.6.1-coverity.patch

189 lines
5.2 KiB
Diff

diff --git a/gnulib/lib/getopt.c b/gnulib/lib/getopt.c
index 7d950af..fa30f13 100644
--- a/gnulib/lib/getopt.c
+++ b/gnulib/lib/getopt.c
@@ -487,7 +487,15 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
const struct option *p;
struct option_list *next;
} *ambig_list = NULL;
+# define free_option_list(l) \
+ while (l != NULL) \
+ { \
+ struct option_list *pn = l->next; \
+ free (l); \
+ l = pn; \
+ }
int exact = 0;
+ int ambig = 0;
int indfound = -1;
int option_index;
@@ -521,15 +529,25 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
{
/* Second or later nonexact match found. */
struct option_list *newp = malloc (sizeof (*newp));
- newp->p = p;
- newp->next = ambig_list;
- ambig_list = newp;
+ if (newp == NULL)
+ {
+ ambig = 1; /* Use simpler fallback message. */
+ free_option_list (ambig_list);
+ ambig_list = NULL;
+ break;
+ }
+ else
+ {
+ newp->p = p;
+ newp->next = ambig_list;
+ ambig_list = newp;
+ }
}
}
- if (ambig_list != NULL && !exact)
+ if ((ambig || ambig_list) && !exact)
{
- if (print_errors)
+ if (print_errors && ambig_list)
{
struct option_list first;
first.p = pfound;
@@ -585,18 +603,20 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
fputc ('\n', stderr);
#endif
}
+ else if (print_errors && ambig)
+ {
+ fprintf (stderr,
+ _("%s: option '%s' is ambiguous\n"),
+ argv[0], argv[d->optind]);
+ }
d->__nextchar += strlen (d->__nextchar);
d->optind++;
d->optopt = 0;
+ free_option_list (ambig_list);
return '?';
}
- while (ambig_list != NULL)
- {
- struct option_list *pn = ambig_list->next;
- free (ambig_list);
- ambig_list = pn;
- }
+ free_option_list (ambig_list);
if (pfound != NULL)
{
diff --git a/lib/decompress.c b/lib/decompress.c
index a176a9d..2be532f 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -48,11 +48,18 @@
static void decompress_zlib (void *data ATTRIBUTE_UNUSED)
{
gzFile zlibfile;
+ int fd;
- zlibfile = gzdopen (dup (STDIN_FILENO), "r");
- if (!zlibfile)
+ fd = dup (STDIN_FILENO);
+ if (fd < 0)
return;
+ zlibfile = gzdopen (fd, "r");
+ if (!zlibfile) {
+ close (fd);
+ return;
+ }
+
for (;;) {
char buffer[4096];
int r = gzread (zlibfile, buffer, 4096);
diff --git a/lib/encodings.c b/lib/encodings.c
index d982827..ec8fb6b 100644
--- a/lib/encodings.c
+++ b/lib/encodings.c
@@ -605,8 +605,10 @@ char *find_charset_locale (const char *charset)
if (setlocale (LC_CTYPE, locale)) {
free (encoding);
goto out;
- } else
+ } else {
+ free (locale);
locale = NULL;
+ }
}
free (encoding);
}
diff --git a/src/man.c b/src/man.c
index cb0930b..12dca6e 100644
--- a/src/man.c
+++ b/src/man.c
@@ -1404,6 +1404,7 @@ static pipeline *make_roff_command (const char *dir, const char *file,
pipeline_command (p, cmd);
}
+ free (fmt_prog);
free (page_encoding);
free (raw_pp_string);
return p;
diff --git a/src/mandb.c b/src/mandb.c
index 550af8f..7ae0d02 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -555,7 +555,7 @@ static int process_manpath (const char *manpath, int global_manpath,
struct tried_catdirs_entry *tried;
struct stat st;
int run_mandb = 0;
- struct dbpaths *dbpaths;
+ struct dbpaths *dbpaths = NULL;
int amount = 0;
if (global_manpath) { /* system db */
@@ -571,8 +571,10 @@ static int process_manpath (const char *manpath, int global_manpath,
tried->seen = 0;
hashtable_install (tried_catdirs, catpath, strlen (catpath), tried);
- if (stat (manpath, &st) < 0 || !S_ISDIR (st.st_mode))
- return 0;
+ if (stat (manpath, &st) < 0 || !S_ISDIR (st.st_mode)) {
+ amount = 0;
+ goto out;
+ }
tried->seen = 1;
if (single_filename) {
@@ -615,10 +617,13 @@ static int process_manpath (const char *manpath, int global_manpath,
#endif /* SECURE_MAN_UID */
out:
- cleanup_sigsafe (dbpaths);
- pop_cleanup (cleanup_sigsafe, dbpaths);
- cleanup (dbpaths);
- pop_cleanup (cleanup, dbpaths);
+ if (dbpaths) {
+ cleanup_sigsafe (dbpaths);
+ pop_cleanup (cleanup_sigsafe, dbpaths);
+ cleanup (dbpaths);
+ pop_cleanup (cleanup, dbpaths);
+ }
+
free (database);
database = NULL;
diff --git a/src/whatis.c b/src/whatis.c
index 4cf14a5..f804c0e 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -810,6 +810,8 @@ nextpage:
free_mandata_elements (&info);
}
+ free (found_here);
+
for (i = 0; i < num_pages; ++i)
free (lowpages[i]);
free (lowpages);