Browse Source

ucimap: Check return of malloc()

Check the return value of malloc() before accessing it.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Hauke Mehrtens 3 years ago
parent
commit
3fbd6c9234
1 changed files with 4 additions and 2 deletions
  1. 4 2
      ucimap.c

+ 4 - 2
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);
 		}