From: Ruben Kerkhof Date: Sat, 23 Apr 2016 09:13:02 +0000 (+0200) Subject: processes plugin: check boundary first X-Git-Tag: collectd-5.6.0~329^2~24 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5aaa5cf763af4c0ba627c202b2daa375227d095a;p=collectd.git processes plugin: check boundary first [src/processes.c:1042]: (style) Array index 'name_start_pos' is used before limits check. --- diff --git a/src/processes.c b/src/processes.c index 5a795b5a..03b44b58 100644 --- a/src/processes.c +++ b/src/processes.c @@ -1038,13 +1038,11 @@ static int ps_read_process (long pid, procstat_t *ps, char *state) * strchr(3) and strrchr(3) to avoid pointer arithmetic which would * otherwise be required to determine name_len. */ name_start_pos = 0; - while ((buffer[name_start_pos] != '(') - && (name_start_pos < buffer_len)) + while (name_start_pos < buffer_len && buffer[name_start_pos] != '(') name_start_pos++; name_end_pos = buffer_len; - while ((buffer[name_end_pos] != ')') - && (name_end_pos > 0)) + while (name_end_pos > 0 && buffer[name_end_pos] != ')') name_end_pos--; /* Either '(' or ')' is not found or they are in the wrong order.