From 8cd3603b9952f224f52044fa2f4e394aae9f854f Mon Sep 17 00:00:00 2001 From: Murai Takashi Date: Thu, 25 Feb 2021 20:30:14 +0900 Subject: [PATCH] compat/freebsd_network: Fix Use of zero-allocated memory If device is not found, 'list' is allocated to size 0. So, modify function to return 0 as FreeBSD's subr_bus.c when 'count' is 0. Pointed out by Clang Static Analyzer. Change-Id: Ice24ae939bfcdb6e1276a86dba40d0b689030fbb Reviewed-on: https://review.haiku-os.org/c/haiku/+/3753 Reviewed-by: Adrien Destugues --- src/libs/compat/freebsd_network/device.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/compat/freebsd_network/device.c b/src/libs/compat/freebsd_network/device.c index 872a8a082e..fa5d69c572 100644 --- a/src/libs/compat/freebsd_network/device.c +++ b/src/libs/compat/freebsd_network/device.c @@ -198,6 +198,12 @@ device_get_children(device_t dev, device_t **devlistp, int *devcountp) count++; } + if (count == 0) { + *devlistp = NULL; + *devcountp = 0; + return (0); + } + list = malloc(count * sizeof(device_t)); if (!list) return (ENOMEM);