From db2f01189563e0bf5dc17c3ca7dc7aa36ab4b148 Mon Sep 17 00:00:00 2001 From: Qualys Security Advisory Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] 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). --- pmap.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pmap.c b/pmap.c index 41116edc..88f6c90b 100644 --- a/pmap.c +++ b/pmap.c @@ -744,26 +744,29 @@ static int one_proc(proc_t * p) return 0; } -static void range_arguments(char *optarg) +static void range_arguments(const char *optarg) { char *arg1; char *arg2; - - arg1 = xstrdup(optarg); + char *const copy = xstrdup(optarg); + if (!copy) + goto fail; + arg1 = copy; arg2 = strchr(arg1, ','); if (arg2) - *arg2 = '\0'; - if (arg2) - ++arg2; + *arg2++ = '\0'; else arg2 = arg1; - if (arg1 && *arg1) + if (*arg1) range_low = STRTOUKL(arg1, &arg1, 16); if (*arg2) range_high = STRTOUKL(arg2, &arg2, 16); - if (arg1 && (*arg1 || *arg2)) - xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"), - optarg); + if (*arg1 || *arg2) + goto fail; + free(copy); + return; +fail: + xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"), optarg); }