From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH 3/3] perf tools: Avoid warning in do_realloc_array_as_needed()
Date: Thu, 16 Mar 2023 21:41:56 +0200 [thread overview]
Message-ID: <20230316194156.8320-4-adrian.hunter@intel.com> (raw)
In-Reply-To: <20230316194156.8320-1-adrian.hunter@intel.com>
do_realloc_array_as_needed() used memcpy() of zero size with a NULL
pointer. Check the size first to avoid sanitize warning.
Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address".
Reported-by: kernel test robot <yujie.liu@intel.com>
Link: https://lore.kernel.org/oe-lkp/202303061424.6ad43294-yujie.liu@intel.com
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/util.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b356c9f7f0c3..089208b51e68 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -524,7 +524,8 @@ int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x, size_t msz,
new_arr = calloc(new_sz, msz);
if (!new_arr)
return -ENOMEM;
- memcpy(new_arr, *arr, *arr_sz * msz);
+ if (*arr_sz)
+ memcpy(new_arr, *arr, *arr_sz * msz);
if (init_val) {
for (i = *arr_sz; i < new_sz; i++)
memcpy(new_arr + (i * msz), init_val, msz);
--
2.34.1
next prev parent reply other threads:[~2023-03-16 19:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 19:41 [PATCH 0/3] perf tools: Address fixes Adrian Hunter
2023-03-16 19:41 ` [PATCH 1/3] perf symbols: Fix use-after-free in get_plt_got_name() Adrian Hunter
2023-03-16 19:41 ` [PATCH 2/3] perf symbols: Fix unaligned access in get_x86_64_plt_disp() Adrian Hunter
2023-03-16 19:41 ` Adrian Hunter [this message]
2023-03-16 21:21 ` [PATCH 0/3] perf tools: Address fixes Ian Rogers
2023-03-29 5:07 ` Adrian Hunter
2023-03-29 12:39 ` Arnaldo Carvalho de Melo
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=20230316194156.8320-4-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.