From: Karel Zak Date: Tue, 22 Jun 2021 14:16:38 +0000 (+0200) Subject: swapon: do not use atoi() X-Git-Tag: v2.37.1~41 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=878307e96099b0b4373635bf4e4a519c8c9da162;p=thirdparty%2Futil-linux.git swapon: do not use atoi() Addresses: https://github.com/karelzak/util-linux/issues/1358 Signed-off-by: Karel Zak --- diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index da836c47ed..ed6be244ec 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -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; }