From: Kristof Provost Date: Wed, 17 May 2023 17:04:19 -0400 Message-ID: In-Reply-To: References: <20230517200143.216-1-chipitsine@...277...> <02835E0F-FA73-4722-83EB-17A33A3A8DA5@...1376...> MIME-Version: 1.0 Subject: Re: [Openvpn-devel] [PATCH] src/openvpn/dco_freebsd.c: handle malloc failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: =?utf-8?b?0JjQu9GM0Y8g0KjQuNC/0LjRhtC40L0=?= Cc: openvpn-devel@lists.sourceforge.net On 17 May 2023, at 16:58, Илья Шипицин wrote: > ср, 17 мая 2023 г. в 22:43, Kristof Provost : > >> On 17 May 2023, at 16:01, Ilya Shipitsin wrote: >>> malloc was not checked against NULL, I was able >>> to get core dump in case of failure >>> >>> Signed-off-by: Ilya Shipitsin >>> --- >>> src/openvpn/dco_freebsd.c | 5 +++++ >>> 1 file changed, 5 insertions(+) >>> >>> diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c >>> index 1111abeb..adbd1120 100644 >>> --- a/src/openvpn/dco_freebsd.c >>> +++ b/src/openvpn/dco_freebsd.c >>> @@ -594,6 +594,11 @@ dco_available(int msglevel) >>> } >>> >>> buf = malloc(ifcr.ifcr_total * IFNAMSIZ); >>> + if (buf == NULL) >>> + { >> >> I’d ‘goto out;’ instead, because that’s how we handle other errors in this >> function. >> (free(NULL) is guaranteed to be safe, so we can just do that.) >> > > on "goto out" we'll end with "return available;" > ‘available’ defaults to ‘false’, so that seems fine to me. Best regards, Kristof