]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
swapon: do not use atoi()
authorKarel Zak <kzak@redhat.com>
Tue, 22 Jun 2021 14:16:38 +0000 (16:16 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Jul 2021 09:49:57 +0000 (11:49 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/swapon.c

index da836c47ed19e595d2d22dc098b9c430b80954d1..ed6be244ec18458a54a9e16239a6e5ada4b0a3d8 100644 (file)
@@ -722,9 +722,15 @@ static int parse_options(struct swap_prop *props, const char *options)
        }
 
        arg = NULL;
-       if (mnt_optstr_get_option(options, "pri", &arg, NULL) == 0 && arg)
-               props->priority = atoi(arg);
-
+       if (mnt_optstr_get_option(options, "pri", &arg, &argsz) == 0 && arg) {
+               char *end = NULL;
+               int n;
+
+               errno = 0;
+               n = (int) strtol(arg, &end, 10);
+               if (errno == 0 && end && end > arg)
+                       props->priority = n;
+       }
        return 0;
 }