public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7683] [libbacktrace] fix up broken test
@ 2023-08-03 13:27 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-08-03 13:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:cc279d6c64562f05019e1d12d0d825f9391b5553

commit r13-7683-gcc279d6c64562f05019e1d12d0d825f9391b5553
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Aug 3 15:21:51 2023 +0200

    [libbacktrace] fix up broken test
    
    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.
    
    libbacktrace/
            * zstdtest.c (test_samples): Properly compute the allocation
            size for the uncompressed data.
    
    (cherry picked from commit a9b6043983b2ebd9d5c0f72043b17110b54f1910)

Diff:
---
 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),

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-03 13:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 13:27 [gcc r13-7683] [libbacktrace] fix up broken test 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).