]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fixed dereference of possibly null head variable in test_deflate_set_header.
authorNathan Moinvaziri <nathan@solidstatenetworks.com>
Mon, 28 Sep 2020 23:43:50 +0000 (16:43 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 9 Oct 2020 09:19:29 +0000 (11:19 +0200)
  example.c:920:16: warning: dereference of possibly-NULL ‘head’ [CWE-690] [-Wanalyzer-possible-null-dereference]

  920 |     head->text = 1;
      |     ~~~~~~~~~~~^~~
  ‘test_deflate_set_header’: event 1
    |
    |  906 |     PREFIX(gz_header) *head = calloc(1, sizeof(PREFIX(gz_header)));
    |      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                               |
    |      |                               (1) this call could return NULL

test/example.c

index 4010c91dc38c8a6d6f81a2158fea6de3613e6519..97ca0029b939f9b3c22dcd641f2063a42f60ce46 100644 (file)
@@ -909,6 +909,11 @@ void test_deflate_set_header(unsigned char *compr, size_t comprLen) {
     size_t len = strlen(hello)+1;
 
 
+    if (head == NULL) {
+        printf("out of memory\n");
+        exit(1);
+    }
+
     c_stream.zalloc = zalloc;
     c_stream.zfree = zfree;
     c_stream.opaque = (voidpf)0;