diff mbox series

[uci,v2,3/4] ucimap: Check return of malloc()

Message ID 20201004151451.16015-4-hauke@hauke-m.de
State Accepted
Delegated to: Petr Štetiar
Headers show
Series uci: Fix multiple bugs | expand

Commit Message

Hauke Mehrtens Oct. 4, 2020, 3:14 p.m. UTC
Check the return value of malloc() before accessing it.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 ucimap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/ucimap.c b/ucimap.c
index 7c2b043..c46cf45 100644
--- a/ucimap.c
+++ b/ucimap.c
@@ -893,14 +893,16 @@  ucimap_parse(struct uci_map *map, struct uci_package *pkg)
 
 			if (sm->alloc) {
 				sd = sm->alloc(map, sm, s);
+				if (!sd)
+					continue;
 				memset(sd, 0, sizeof(struct ucimap_section_data));
 			} else {
 				sd = malloc(sm->alloc_len);
+				if (!sd)
+					continue;
 				memset(sd, 0, sm->alloc_len);
 				sd = ucimap_ptr_section(sm, sd);
 			}
-			if (!sd)
-				continue;
 
 			ucimap_parse_section(map, sm, sd, s);
 		}