From 165b0f1d1082f10b95d34e69399d7dec0b29e216 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:21:28 +0000 Subject: [PATCH] iscsi-scstd: Improve create_and_open_dev() robustness Reset 'devn' if the sscanf() return value is lower than two. Based on a Coverity report. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6367 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/misc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/iscsi-scst/usr/misc.c b/iscsi-scst/usr/misc.c index 357be4d11..13c7676e8 100644 --- a/iscsi-scst/usr/misc.c +++ b/iscsi-scst/usr/misc.c @@ -43,12 +43,9 @@ int create_and_open_dev(const char *dev, int readonly) } devn = 0; - while (!feof(f)) { - if (!fgets(buf, sizeof(buf), f)) - break; - if (sscanf(buf, "%d %s", &devn, devname) != 2) - continue; - if (!strcmp(devname, dev)) + while (fgets(buf, sizeof(buf), f)) { + if (sscanf(buf, "%d %s", &devn, devname) == 2 && + devn > 0 && strcmp(devname, dev) == 0) break; devn = 0; }