pmap: Plug memory leak in range_arguments().

Also, simplify the code slightly (but functionally equivalent). Check
the return value of xstrdup() only once (yes, it can return NULL).
This commit is contained in:
Qualys Security Advisory 1970-01-01 00:00:00 +00:00 committed by Craig Small
parent 14758ebc8f
commit db2f011895

23
pmap.c
View File

@ -744,26 +744,29 @@ static int one_proc(proc_t * p)
return 0; return 0;
} }
static void range_arguments(char *optarg) static void range_arguments(const char *optarg)
{ {
char *arg1; char *arg1;
char *arg2; char *arg2;
char *const copy = xstrdup(optarg);
arg1 = xstrdup(optarg); if (!copy)
goto fail;
arg1 = copy;
arg2 = strchr(arg1, ','); arg2 = strchr(arg1, ',');
if (arg2) if (arg2)
*arg2 = '\0'; *arg2++ = '\0';
if (arg2)
++arg2;
else else
arg2 = arg1; arg2 = arg1;
if (arg1 && *arg1) if (*arg1)
range_low = STRTOUKL(arg1, &arg1, 16); range_low = STRTOUKL(arg1, &arg1, 16);
if (*arg2) if (*arg2)
range_high = STRTOUKL(arg2, &arg2, 16); range_high = STRTOUKL(arg2, &arg2, 16);
if (arg1 && (*arg1 || *arg2)) if (*arg1 || *arg2)
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"), goto fail;
optarg); free(copy);
return;
fail:
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"), optarg);
} }