]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
eject: do not use atoi()
authorKarel Zak <kzak@redhat.com>
Tue, 22 Jun 2021 13:15:46 +0000 (15:15 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 22 Jun 2021 15:04:24 +0000 (17:04 +0200)
* remove unnecessary strtok() use
* remove atoi use()

Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/eject.c

index 457ce0d081f08758763e4ec57beead44a674651c..d534b61b6d19a39dc9dae8748b11e91474e88b43 100644 (file)
@@ -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 ");
+                               fclose(f);
+
+                               str = line + 12;
+                               normalize_whitespace((unsigned char *) str);
 
-                               if (!str)
-                                       errx(EXIT_FAILURE,
-                                               _("%s: failed to read speed"),
+                               if (ul_strtou64(str, &n, 10) == 0 && n <= INT_MAX)
+                                       return (int) n;
+
+                               errx(EXIT_FAILURE, _("%s: failed to read speed"),
                                                _PATH_PROC_CDROMINFO);
-                               fclose(f);
-                               return atoi(str);
                        }
                }
        }