]> granicus.if.org Git - graphviz/commitdiff
cgraph memresize: fix out-of-bounds write on allocation failure
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 27 Aug 2022 15:45:31 +0000 (08:45 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 30 Aug 2022 01:19:51 +0000 (18:19 -0700)
Callers of this function appear to anticipate the possibility of failure, e.g.
`agrealloc`. But the function itself was attempting to zero newly allocated
memory even if the allocation call failed.

lib/cgraph/mem.c

index fb30fa81254844b6f847ef983b8608153a918123..bdc131f48aafb050f8f330f792a5a0d778ff5081 100644 (file)
@@ -34,7 +34,7 @@ static void *memresize(void *heap, void *ptr, size_t oldsize,
 
     (void)heap;
     rv = realloc(ptr, request);
-    if (request > oldsize)
+    if (rv != NULL && request > oldsize)
        memset((char *) rv + oldsize, 0, request - oldsize);
     return rv;
 }