From: Karel Zak Date: Mon, 21 Jun 2021 13:37:48 +0000 (+0200) Subject: readprofile: check errno after strto..() X-Git-Tag: v2.38-rc1~403 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e5e56eb0ad620adfd1c26e1a9b3a09a59154165;p=thirdparty%2Futil-linux.git readprofile: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 7f6b5f882f..e55363484e 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -125,6 +125,7 @@ usrsbin_exec_PROGRAMS += readprofile MANPAGES += sys-utils/readprofile.8 dist_noinst_DATA += sys-utils/readprofile.8.adoc readprofile_SOURCES = sys-utils/readprofile.c +readprofile_LDADD = $(LDADD) libcommon.la endif if BUILD_TUNELP diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c index a89fd180c9..00d9970aa8 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -51,6 +51,8 @@ #include #include +#include "c.h" +#include "strutils.h" #include "nls.h" #include "xalloc.h" #include "closestream.h" @@ -130,8 +132,8 @@ static void __attribute__((__noreturn__)) usage(void) int main(int argc, char **argv) { FILE *map; - int proFd; - char *mapFile, *proFile, *mult = NULL; + int proFd, has_mult = 0, multiplier = 0; + char *mapFile, *proFile; size_t len = 0, indx = 1; unsigned long long add0 = 0; unsigned int step; @@ -199,7 +201,8 @@ int main(int argc, char **argv) optInfo++; break; case 'M': - mult = optarg; + multiplier = strtol_or_err(optarg, _("failed to parse multiplier")); + has_mult = 1; break; case 'r': optReset++; @@ -217,14 +220,13 @@ int main(int argc, char **argv) } } - if (optReset || mult) { - int multiplier, fd, to_write; + if (optReset || has_mult) { + int fd, to_write; /* When writing the multiplier, if the length of the * write is not sizeof(int), the multiplier is not * changed. */ - if (mult) { - multiplier = strtoul(mult, NULL, 10); + if (has_mult) { to_write = sizeof(int); } else { multiplier = 0;