0085-pmap.c: 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).

Adapted slightly to remove goto and leave the format of checks the same.
A lot of the fixes were already in newlib, caught by coverity

References:
 commit 25f655891f

Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
Qualys Security Advisory 1970-01-01 00:00:00 +00:00 committed by Craig Small
parent a016a43b53
commit 105ab093b8

13
pmap.c
View File

@ -747,24 +747,25 @@ static int one_proc (struct pids_stack *p)
return 0;
}
static void range_arguments(char *optarg)
static void range_arguments(const char *optarg)
{
char *buf, *arg1, *arg2;
buf = xstrdup(optarg);
if ((buf = xstrdup(optarg)) == NULL) {
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"),
optarg);
}
arg1 = buf;
arg2 = strchr(arg1, ',');
if (arg2)
*arg2 = '\0';
if (arg2)
++arg2;
*arg2++ = '\0';
else
arg2 = arg1;
if (arg1[0] != '\0')
range_low = strtoul(arg1, &arg1, 16);
if (arg2[0] != '\0')
range_high = strtoul(arg2, &arg2, 16);
if (arg1 && (*arg1 || *arg2)) {
if (*arg1 || *arg2) {
free(buf);
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"),
optarg);