[haiku-commits] Change in haiku[master]: compat/freebsd_network: Fix Use of zero-allocated memory

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 25 Feb 2021 20:56:48 +0000

From Murai Takashi <tmurai01@xxxxxxxxx>:

Murai Takashi has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3753 ;)


Change subject: compat/freebsd_network: Fix Use of zero-allocated memory
......................................................................

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
---
M src/libs/compat/freebsd_network/device.c
1 file changed, 6 insertions(+), 0 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/53/3753/1

diff --git a/src/libs/compat/freebsd_network/device.c 
b/src/libs/compat/freebsd_network/device.c
index 872a8a0..fa5d69c 100644
--- a/src/libs/compat/freebsd_network/device.c
+++ b/src/libs/compat/freebsd_network/device.c
@@ -198,6 +198,12 @@
                count++;
        }

+       if (count == 0) {
+               *devlistp = NULL;
+               *devcountp = 0;
+               return (0);
+       }
+
        list = malloc(count * sizeof(device_t));
        if (!list)
                return (ENOMEM);

--
To view, visit https://review.haiku-os.org/c/haiku/+/3753
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ice24ae939bfcdb6e1276a86dba40d0b689030fbb
Gerrit-Change-Number: 3753
Gerrit-PatchSet: 1
Gerrit-Owner: Murai Takashi <tmurai01@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: compat/freebsd_network: Fix Use of zero-allocated memory - Gerrit