Skip to content

Commit f8b0e05

Browse files
author
David Sommerseth
committed
Fix missing error checking when reading /proc/net/dev
Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent 052d432 commit f8b0e05

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python-ethtool/ethtool.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static PyObject *get_active_devices(PyObject *self __unused, PyObject *args __un
8080
static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
8181
{
8282
char buffer[256];
83-
char *ret;;
83+
char *ret;
8484
PyObject *list = PyList_New(0);
8585
FILE *fd = fopen(_PATH_PROCNET_DEV, "r");
8686

@@ -89,7 +89,13 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
8989
return NULL;
9090
}
9191
/* skip over first two lines */
92-
ret = fgets(buffer, 256, fd); ret = fgets(buffer, 256, fd);
92+
ret = fgets(buffer, 256, fd);
93+
ret = fgets(buffer, 256, fd);
94+
if( !ret ) {
95+
PyErr_SetString(PyExc_OSError, strerror(errno));
96+
return NULL;
97+
}
98+
9399
while (!feof(fd)) {
94100
PyObject *str;
95101
char *name = buffer;

0 commit comments

Comments
 (0)