Skip to content

Commit a950707

Browse files
committed
Fix bad loop condition within get_devices()
get_devices() includes this loop: char buffer[256]; ...snip... char *end = buffer; ...snip... while (end && *end != ':') end++; The condition "end" within the while guard will always be true, given that buffer is on the stack and thus will never be near the zero value. It should be *end instead, to check for the NUL terminator byte: this code will likely crash if the string does not contain a colon character. This appears to have been present in the initial commit of the code (8d6ad99) Found by Braňo Náter using the "cppcheck" static analyzer.
1 parent d134c6c commit a950707

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

python-ethtool/ethtool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
129129
if (fgets(buffer, 256, fd) == NULL)
130130
break;
131131
/* find colon */
132-
while (end && *end != ':')
132+
while (*end && *end != ':')
133133
end++;
134134
*end = 0; /* terminate where colon was */
135135
while (*name == ' ')

0 commit comments

Comments
 (0)