]> granicus.if.org Git - psmisc/commitdiff
killall: minor str length changes
authorCraig Small <csmall@dropbear.xyz>
Mon, 2 Mar 2020 10:56:02 +0000 (21:56 +1100)
committerCraig Small <csmall@dropbear.xyz>
Mon, 2 Mar 2020 10:56:02 +0000 (21:56 +1100)
reworked some of the string handling to check for strchr and
strrchr return values. Removed check for unsigned to be negative,
that's not going to happen!

References:
 Coverity 288525

src/killall.c

index 557fa51c9b217dc6552952f81a087fc6545cf455..524760be86abca6a3830978ecd4ebb2a8c9fdaf7 100644 (file)
@@ -345,11 +345,12 @@ load_process_name_and_age(char *comm, double *process_age_sec,
         return -1;
     }
     fclose(file);
-    startcomm = strchr(buf, '(') + 1;
-    endcomm = strrchr(startcomm, ')');
+    if ( NULL == ( startcomm = strchr(buf, '(')))
+       return -1;
+    startcomm++;
+    if ( NULL == ( endcomm = strrchr(startcomm, ')')))
+       return -1;
     lencomm = endcomm - startcomm;
-    if (lencomm < 0)
-        lencomm = 0;
     if (lencomm > COMM_LEN -1)
         lencomm = COMM_LEN -1;
     strncpy(comm, startcomm, lencomm);