From: Craig Small Date: Mon, 2 Mar 2020 10:56:02 +0000 (+1100) Subject: killall: minor str length changes X-Git-Tag: v23.4rc1~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8df09a2792712a8852d637d07902896784721228;p=psmisc killall: minor str length changes 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 --- diff --git a/src/killall.c b/src/killall.c index 557fa51..524760b 100644 --- a/src/killall.c +++ b/src/killall.c @@ -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);