diff mbox series

[iproute] lib: names: check calloc return value in db_names_alloc

Message ID 20241113105219.29134-1-kirjanov@gmail.com (mailing list archive)
State Superseded
Headers show
Series [iproute] lib: names: check calloc return value in db_names_alloc | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Denis Kirjanov Nov. 13, 2024, 10:52 a.m. UTC
db_names_load() may crash since it touches the
hash member. Fix it by checking the return value

Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
---
 lib/names.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/lib/names.c b/lib/names.c
index cbfa971f..4ecae92b 100644
--- a/lib/names.c
+++ b/lib/names.c
@@ -55,6 +55,10 @@  struct db_names *db_names_alloc(void)
 
 	db->size = MAX_ENTRIES;
 	db->hash = calloc(db->size, sizeof(struct db_entry *));
+	if (!db->hash) {
+		free(db);
+		return NULL;
+	}
 
 	return db;
 }