chiark / gitweb /
bootchart: parse userinput with safe_atoi
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Fri, 26 Sep 2014 19:41:02 +0000 (21:41 +0200)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sun, 28 Sep 2014 12:46:38 +0000 (14:46 +0200)
Found by coverity. Fixes: CID#996409

src/bootchart/store.c

index ed683e88d97472fb11c42ea5c55c2dd1cf1ca656..3099ff12083a8271df27ad24c4b646c037c404fd 100644 (file)
@@ -192,12 +192,14 @@ vmstat_next:
 
         m = buf;
         while (m) {
+                int r;
+
                 if (sscanf(m, "%s %*s %*s %*s %*s %*s %*s %s %s", key, rt, wt) < 3)
                         goto schedstat_next;
 
                 if (strstr(key, "cpu")) {
-                        c = atoi((const char*)(key+3));
-                        if (c > MAXCPUS)
+                        r = safe_atoi((const char*)(key+3), &c);
+                        if (r < 0 || c > MAXCPUS)
                                 /* Oops, we only have room for MAXCPUS data */
                                 break;
                         sampledata->runtime[c] = atoll(rt);