From 8df09a2792712a8852d637d07902896784721228 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Mon, 2 Mar 2020 21:56:02 +1100 Subject: [PATCH 09/20] 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 https://gitlab.com/psmisc/psmisc/-/commit/8df09a2792712a8852d637d07902896784721228 --- src/killall.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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); -- 2.22.0.windows.1