readprofile: check errno after strto..()
Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
95bfc92361
commit
3e5e56eb0a
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue