]> granicus.if.org Git - procps-ng/commitdiff
pgrep: fix potential null derefences [smatch scan]
authorSami Kerola <kerolasa@iki.fi>
Sun, 5 Feb 2012 20:10:53 +0000 (21:10 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 5 Feb 2012 20:13:36 +0000 (21:13 +0100)
pgrep.c:137 split_list(19) error: potential null derefence 'list'.
pgrep.c:540 select_procs(106) error: potential null derefence 'list'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
pgrep.c

diff --git a/pgrep.c b/pgrep.c
index b5d72365a828826cd634f0471eddd332a2db99ff..d4c2665b1694af3ec6fbd0a1abfb8bba988e88e1 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -134,7 +134,7 @@ static struct el *split_list (const char *restrict str, int (*convert)(const cha
                if (sep_pos)
                        *sep_pos = 0;
                // Use ++i instead of i++ because slot zero is a count
-               if (!convert (ptr, &list[++i]))
+               if (list && !convert (ptr, &list[++i]))
                        exit (EXIT_USAGE);
                if (sep_pos)
                        ptr = sep_pos + 1;
@@ -535,12 +535,14 @@ static struct el * select_procs (int *num)
                                size = size * 5 / 4 + 4;
                                list = xrealloc(list, size * sizeof *list);
                        }
-                       if (opt_long || opt_echo) {
+                       if (list && (opt_long || opt_echo)) {
                                char buff[5096];  // FIXME
                                list[matches].num = task.XXXID;
                                list[matches++].str = xstrdup (cmd);
-                       } else {
+                       } else if (list) {
                                list[matches++].num = task.XXXID;
+                       } else {
+                               xerrx(EXIT_FAILURE, _("internal error"));
                        }
                }