]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
readprofile: check errno after strto..()
authorKarel Zak <kzak@redhat.com>
Mon, 21 Jun 2021 13:37:48 +0000 (15:37 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 21 Jun 2021 13:37:48 +0000 (15:37 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/Makemodule.am
sys-utils/readprofile.c

index 7f6b5f882f46c4997097c192fa957e0644e1d71f..e55363484e1fdac6765ac43ce9085e375c2193f7 100644 (file)
@@ -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
index a89fd180c9b615987ffdfa22df589572bb9db61c..00d9970aa81245eea1b1b8d1d2fe28bf9f64a489 100644 (file)
@@ -51,6 +51,8 @@
 #include <sys/utsname.h>
 #include <unistd.h>
 
+#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;