]> granicus.if.org Git - procps-ng/commitdiff
0086-pmap: Prevent integer overflow in main().
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Sat, 23 Jun 2018 11:59:14 +0000 (21:59 +1000)
Unlikely to ever happen, but just in case.

Signed-off-by: Craig Small <csmall@enc.com.au>
pmap.c

diff --git a/pmap.c b/pmap.c
index 77e363e07177478a53f3de37fa62d62f3a073335..6c1abc4238102a06803b17ff9eabbe04b2b77d5c 100644 (file)
--- a/pmap.c
+++ b/pmap.c
@@ -30,6 +30,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <assert.h>
+#include <limits.h>
 
 #include "c.h"
 #include "fileutils.h"
@@ -1136,6 +1137,8 @@ int main(int argc, char **argv)
                        }
                }
        }
+       if ((size_t)argc >= INT_MAX / sizeof(pid_t))
+               xerrx(EXIT_FAILURE, _("too many arguments"));
        if (procps_pids_new(&Pids_info, Pid_items, 4))
                xerrx(EXIT_FAILURE, _("library failed pids statistics"));
        pidlist = xmalloc(sizeof(pid_t) * argc);