From ab78e6ae616ca821ca5d1d21b0874dc5151aed35 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 5 May 2015 10:43:43 +0200 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. Signed-off-by: Bart Van Assche --- 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; }