]> granicus.if.org Git - graphviz/commitdiff
pathplan Pobsopen: fix unchecked allocation failures
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 30 Jul 2022 16:29:47 +0000 (09:29 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 5 Aug 2022 13:52:10 +0000 (06:52 -0700)
The first `malloc` of `rv` was checked for failure but the subsequent ones were
assumed to succeed.

lib/pathplan/cvt.c

index f22bd5d58bcf0b6a6ce1a1998ba9f5ec2e7bc616..3e1c9ce0fc495a716a378ef8a135d58e1334204b 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <cgraph/likely.h>
 #include <pathplan/vis.h>
 
 typedef Ppoint_t ilcoord_t;
@@ -49,6 +50,18 @@ vconfig_t *Pobsopen(Ppoly_t ** obs, int n_obs)
     rv->N = n;
     rv->Npoly = n_obs;
 
+    // bail out if any above allocations failed
+    if (UNLIKELY(rv->start == NULL || (n > 0 && (rv->P == NULL ||
+                                                 rv->next == NULL ||
+                                                 rv->prev == NULL)))) {
+       free(rv->prev);
+       free(rv->next);
+       free(rv->start);
+       free(rv->P);
+       free(rv);
+       return NULL;
+    }
+
     /* build arrays */
     i = 0;
     for (poly_i = 0; poly_i < n_obs; poly_i++) {