]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[libbacktrace] fix up broken test
authorRichard Biener <rguenther@suse.de>
Thu, 3 Aug 2023 13:21:51 +0000 (15:21 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 3 Aug 2023 13:26:04 +0000 (15:26 +0200)
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.

libbacktrace/zstdtest.c

index 1b4158a50ebb251a187494c7248dd86d44674618..1a27d90e29e03c50840dcf19af10325126b90318 100644 (file)
@@ -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),