From: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx> Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx> --- usr/bs_sg.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/usr/bs_sg.c b/usr/bs_sg.c index 4f78def..fe7dbec 100644 --- a/usr/bs_sg.c +++ b/usr/bs_sg.c @@ -301,19 +301,27 @@ static void bs_sg_cmd_complete(int fd, int events, void *data) static int get_bsg_major(char *path) { FILE *devfd; - char majorno[8]; + int majorno, n; char dev[64]; char tmp[16]; sscanf(path, "/dev/bsg/%s", tmp); sprintf(dev, "/sys/class/bsg/%s/dev", tmp); devfd = fopen(dev, "r"); - if (!devfd) + if (!devfd) { + eprintf("%s open failed errno: %d\n", dev, errno); return -1; - fscanf(devfd, "%s:", majorno); + } + n = fscanf(devfd, "%d:", &majorno); fclose(devfd); - - return atoi(majorno); + if (n != 1) { + if (n < 0) + eprintf("reading major from %s failed errno: %d\n", dev, errno); + else + eprintf("reading major from %s failed: invalid input\n", dev); + return -1; + } + return majorno; } static int chk_sg_device(char *path) -- 1.7.9.6 -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html