From aeba558136d2082fd01939905bbb4d323f54c34c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 21 Jun 2021 15:37:48 +0200 Subject: [PATCH] readprofile: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- sys-utils/Makemodule.am | 1 + sys-utils/readprofile.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 7f6b5f882..e55363484 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 a89fd180c..00d9970aa 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;