Blob Blame History Raw
From f8b0e05c03add3d0bd7736c3e3f81e8eb28bc7c3 Mon Sep 17 00:00:00 2001
From: David Sommerseth <davids@redhat.com>
Date: Fri, 13 Sep 2013 18:54:05 +0200
Subject: [PATCH] Fix missing error checking when reading /proc/net/dev

Signed-off-by: David Sommerseth <davids@redhat.com>
---
 python-ethtool/ethtool.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c
index e58d5f9..a471726 100644
--- a/python-ethtool/ethtool.c
+++ b/python-ethtool/ethtool.c
@@ -80,7 +80,7 @@ static PyObject *get_active_devices(PyObject *self __unused, PyObject *args __un
 static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
 {
 	char buffer[256];
-	char *ret;;
+	char *ret;
 	PyObject *list = PyList_New(0);
 	FILE *fd = fopen(_PATH_PROCNET_DEV, "r");
 
@@ -89,7 +89,13 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
 		return NULL;
 	}
 	/* skip over first two lines */
-	ret = fgets(buffer, 256, fd); ret = fgets(buffer, 256, fd);
+	ret = fgets(buffer, 256, fd);
+	ret = fgets(buffer, 256, fd);
+	if( !ret ) {
+		PyErr_SetString(PyExc_OSError, strerror(errno));
+		return NULL;
+	}
+
 	while (!feof(fd)) {
 		PyObject *str;
 		char *name = buffer;