From a1b3e2ec9d13070bccc51ccf64c8cd634ae3d172 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 22 Jun 2021 15:15:46 +0200 Subject: [PATCH] eject: do not use atoi() * remove unnecessary strtok() use * remove atoi use() Addresses: https://github.com/karelzak/util-linux/issues/1358 Signed-off-by: Karel Zak --- sys-utils/eject.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sys-utils/eject.c b/sys-utils/eject.c index 457ce0d08..d534b61b6 100644 --- a/sys-utils/eject.c +++ b/sys-utils/eject.c @@ -526,18 +526,18 @@ static int read_speed(const char *devname) /* find line "drive speed" and read the correct speed */ } else { if (strncmp(line, "drive speed:", 12) == 0) { - int i; + uint64_t n; - str = strtok(&line[12], "\t "); - for (i = 1; i < drive_number; i++) - str = strtok(NULL, "\t "); - - if (!str) - errx(EXIT_FAILURE, - _("%s: failed to read speed"), - _PATH_PROC_CDROMINFO); fclose(f); - return atoi(str); + + str = line + 12; + normalize_whitespace((unsigned char *) str); + + if (ul_strtou64(str, &n, 10) == 0 && n <= INT_MAX) + return (int) n; + + errx(EXIT_FAILURE, _("%s: failed to read speed"), + _PATH_PROC_CDROMINFO); } } }