public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] [libbacktrace] fix up broken test
       [not found] <20230803132707.9869D3858C30@sourceware.org>
@ 2023-08-03 18:47 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2023-08-03 18:47 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Thu, Aug 3, 2023 at 6:27 AM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> zstdtest has some inline data where some testcases lack the
> uncompressed length field.  Thus it computes that but still
> ends up allocating memory for the uncompressed buffer based on
> that (zero) length.  Oops.  Causes memory corruption if the
> allocator returns non-NULL.
>
> Tested on x86_64-unknown-linux-gnu, pushed as obvious.
>
> libbacktrace/
>         * zstdtest.c (test_samples): Properly compute the allocation
>         size for the uncompressed data.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] [libbacktrace] fix up broken test
@ 2023-08-03 13:26 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-08-03 13:26 UTC (permalink / raw)
  To: gcc-patches

zstdtest has some inline data where some testcases lack the
uncompressed length field.  Thus it computes that but still
ends up allocating memory for the uncompressed buffer based on
that (zero) length.  Oops.  Causes memory corruption if the
allocator returns non-NULL.

Tested on x86_64-unknown-linux-gnu, pushed as obvious.

libbacktrace/
	* zstdtest.c (test_samples): Properly compute the allocation
	size for the uncompressed data.
---
 libbacktrace/zstdtest.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libbacktrace/zstdtest.c b/libbacktrace/zstdtest.c
index 1b4158a50eb..1a27d90e29e 100644
--- a/libbacktrace/zstdtest.c
+++ b/libbacktrace/zstdtest.c
@@ -197,7 +197,11 @@ test_samples (struct backtrace_state *state)
       unsigned char *uncompressed;
       size_t uncompressed_len;
 
-      uncompressed = (unsigned char *) malloc (tests[i].uncompressed_len);
+      uncompressed_len = tests[i].uncompressed_len;
+      if (uncompressed_len == 0)
+	uncompressed_len = strlen (tests[i].uncompressed);
+
+      uncompressed = (unsigned char *) malloc (uncompressed_len);
       if (uncompressed == NULL)
 	{
 	  perror ("malloc");
@@ -206,10 +210,6 @@ test_samples (struct backtrace_state *state)
 	  continue;
 	}
 
-      uncompressed_len = tests[i].uncompressed_len;
-      if (uncompressed_len == 0)
-	uncompressed_len = strlen (tests[i].uncompressed);
-
       if (!backtrace_uncompress_zstd (state,
 				      ((const unsigned char *)
 				       tests[i].compressed),
-- 
2.35.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-03 18:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230803132707.9869D3858C30@sourceware.org>
2023-08-03 18:47 ` [PATCH] [libbacktrace] fix up broken test Ian Lance Taylor
2023-08-03 13:26 Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).