From: Jann Horn <jannh@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] tools: Fix realloc() use in fdarray__grow()
Date: Sat, 29 Feb 2020 17:26:07 +0100 [thread overview]
Message-ID: <20200229162607.6000-1-jannh@google.com> (raw)
If `entries != NULL`, then `fda->entries` has been freed, so whatever
happens afterwards, we must store `entries` in `fda->entries`.
If we bail out at the second realloc(), the new allocation will be bigger
than what fda->nr_alloc says, but that's fine.
Fixes: 2171a9256862 ("tools lib fd array: Allow associating an integer cookie with each entry")
Signed-off-by: Jann Horn <jannh@google.com>
---
To the maintainer:
I'm not sure about the etiquette for using CC stable in
patches for somewhat theoretical issues in userland tools;
feel free to tack a CC stable onto this if you think it
should go into stable.
tools/lib/api/fd/array.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/lib/api/fd/array.c b/tools/lib/api/fd/array.c
index 58d44d5eee31..acf8eca1a94a 100644
--- a/tools/lib/api/fd/array.c
+++ b/tools/lib/api/fd/array.c
@@ -27,15 +27,13 @@ int fdarray__grow(struct fdarray *fda, int nr)
if (entries == NULL)
return -ENOMEM;
+ fda->entries = entries;
priv = realloc(fda->priv, psize);
- if (priv == NULL) {
- free(entries);
+ if (priv == NULL)
return -ENOMEM;
- }
fda->nr_alloc = nr_alloc;
- fda->entries = entries;
fda->priv = priv;
return 0;
}
--
2.25.0
next reply other threads:[~2020-02-29 16:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-29 16:26 Jann Horn [this message]
2020-03-02 12:58 ` Jiri Olsa
2020-03-02 14:54 ` Jann Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200229162607.6000-1-jannh@google.com \
--to=jannh@google.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®