aboutsummaryrefslogtreecommitdiff
path: root/sys/boot/efi/libefi/efinet.c
diff options
context:
space:
mode:
authorToomas Soome <tsoome@FreeBSD.org>2017-01-18 08:18:07 +0000
committerToomas Soome <tsoome@FreeBSD.org>2017-01-18 08:18:07 +0000
commit9c1cd3f5c3135086eb2c4ba9f82acc926e1c3667 (patch)
tree6dc7e3ac1d4a8eacc71d8c5e2c052587b6ebb784 /sys/boot/efi/libefi/efinet.c
parent18e367f4aa4b5780a045398d72f26044cb9e5e09 (diff)
downloadsrc-9c1cd3f5c3135086eb2c4ba9f82acc926e1c3667.tar.gz
src-9c1cd3f5c3135086eb2c4ba9f82acc926e1c3667.zip
loader: efi devpath api usage should be more aware of NULL pointers
As the efi_devpath_last_node() and efi_devpath_trim() can return NULL pointers, the consumers of this API should check the the NULL pointers. Same for efinet_dev_init() using calloc(). Reported by: Robert Mustacchi <rm@joyent.com> Reviewed by: jhb, allanjude Approved by: allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D9203
Notes
Notes: svn path=/head/; revision=312374
Diffstat (limited to 'sys/boot/efi/libefi/efinet.c')
-rw-r--r--sys/boot/efi/libefi/efinet.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/sys/boot/efi/libefi/efinet.c b/sys/boot/efi/libefi/efinet.c
index 1207088d8682..26802c2287d9 100644
--- a/sys/boot/efi/libefi/efinet.c
+++ b/sys/boot/efi/libefi/efinet.c
@@ -291,12 +291,18 @@ efinet_dev_init()
if (EFI_ERROR(status))
return (efi_status_to_errno(status));
handles2 = (EFI_HANDLE *)malloc(sz);
+ if (handles2 == NULL) {
+ free(handles);
+ return (ENOMEM);
+ }
nifs = 0;
for (i = 0; i < sz / sizeof(EFI_HANDLE); i++) {
devpath = efi_lookup_devpath(handles[i]);
if (devpath == NULL)
continue;
- node = efi_devpath_last_node(devpath);
+ if ((node = efi_devpath_last_node(devpath)) == NULL)
+ continue;
+
if (DevicePathType(node) != MESSAGING_DEVICE_PATH ||
DevicePathSubType(node) != MSG_MAC_ADDR_DP)
continue;
@@ -318,20 +324,24 @@ efinet_dev_init()
}
free(handles);
if (nifs == 0) {
- free(handles2);
- return (ENOENT);
+ err = ENOENT;
+ goto done;
}
err = efi_register_handles(&efinet_dev, handles2, NULL, nifs);
- if (err != 0) {
- free(handles2);
- return (err);
- }
+ if (err != 0)
+ goto done;
- efinetif.netif_nifs = nifs;
efinetif.netif_ifs = calloc(nifs, sizeof(struct netif_dif));
-
stats = calloc(nifs, sizeof(struct netif_stats));
+ if (efinetif.netif_ifs == NULL || stats == NULL) {
+ free(efinetif.netif_ifs);
+ free(stats);
+ efinetif.netif_ifs = NULL;
+ err = ENOMEM;
+ goto done;
+ }
+ efinetif.netif_nifs = nifs;
for (i = 0; i < nifs; i++) {
@@ -341,9 +351,9 @@ efinet_dev_init()
dif->dif_stats = &stats[i];
dif->dif_private = handles2[i];
}
+done:
free(handles2);
-
- return (0);
+ return (err);
}
static int