diff mbox series

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

Message ID 20241113105349.29327-1-kirjanov@gmail.com (mailing list archive)
State Accepted
Commit 225f74761b091e51444cf1f9686547f3c42e44b3
Delegated to: Stephen Hemminger
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:53 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(+)

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 17, 2024, 6:20 p.m. UTC | #1
Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Wed, 13 Nov 2024 13:53:49 +0300 you wrote:
> 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(+)

Here is the summary with links:
  - [iproute] lib: names: check calloc return value in db_names_alloc
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=225f74761b09

You are awesome, thank you!
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;
 }