From: Andrew Bays Date: Wed, 13 Dec 2017 17:50:13 +0000 (-0500) Subject: check fscanf return value in process_check X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6c5718e65a49ee171e1ccec5e67fdb1b55a69b43;p=collectd.git check fscanf return value in process_check --- diff --git a/src/procevent.c b/src/procevent.c index e4f473be..e05fa0c8 100644 --- a/src/procevent.c +++ b/src/procevent.c @@ -103,7 +103,7 @@ static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); // Does /proc//comm contain a process name we are interested in? static processlist_t *process_check(int pid) { - int len, is_match, status; + int len, is_match, status, retval; char file[BUFSIZE]; FILE *fh; char buffer[BUFSIZE]; @@ -122,7 +122,13 @@ static processlist_t *process_check(int pid) { return NULL; } - fscanf(fh, "%[^\n]", buffer); + retval = fscanf(fh, "%[^\n]", buffer); + + if (retval < 0) { + WARNING("procevent process_check: unable to read comm file for pid %d", + pid); + return NULL; + } // // Go through the processlist linked list and look for the process name