]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
infcover.c: assert that we avoid zero-length allocations; fixes #593
authorDan Kegel <dank@kegel.com>
Sat, 13 Jun 2020 19:17:46 +0000 (19:17 +0000)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Mon, 15 Jun 2020 08:46:07 +0000 (10:46 +0200)
test/infcover.c

index 10baaad540febd6108eaae3b23e31f630726a622..9f98bd5c3fbe833f615fcdaf2cce628001a11728 100644 (file)
@@ -242,8 +242,11 @@ static void mem_done(PREFIX3(stream) *strm, char *prefix) {
 static unsigned char *h2b(const char *hex, unsigned *len) {
     unsigned char *in, *re;
     unsigned next, val;
+    unsigned inlen;
 
-    in = malloc((strlen(hex) + 1) >> 1);
+    inlen = (strlen(hex) + 1) >> 1;
+    assert(inlen != 0);     /* tell static analyzer we won't call malloc(0) */
+    in = malloc(inlen);
     if (in == NULL)
         return NULL;
     next = 0;
@@ -264,6 +267,7 @@ static unsigned char *h2b(const char *hex, unsigned *len) {
     } while (*hex++);       /* go through the loop with the terminating null */
     if (len != NULL)
         *len = next;
+    assert(next != 0);      /* tell static analyzer we won't call realloc(in, 0) */
     re = realloc(in, next);
     return re == NULL ? in : re;
 }