From: Matthew Fernandez Date: Sat, 30 Jul 2022 16:29:47 +0000 (-0700) Subject: pathplan Pobsopen: fix unchecked allocation failures X-Git-Tag: 5.0.1~21^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7033e6a48e6f4105cb114507d775292c2ab6bc12;p=graphviz pathplan Pobsopen: fix unchecked allocation failures The first `malloc` of `rv` was checked for failure but the subsequent ones were assumed to succeed. --- diff --git a/lib/pathplan/cvt.c b/lib/pathplan/cvt.c index f22bd5d58..3e1c9ce0f 100644 --- a/lib/pathplan/cvt.c +++ b/lib/pathplan/cvt.c @@ -10,6 +10,7 @@ #include #include +#include #include 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++) {