From 12c3298335c48fcdd1551c1474f9afe07e9a067f Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 24 Feb 2024 17:13:06 +0100 Subject: irmd: Fix wrong hash length when getting ipcpd The get_ipcpd_by_dst function was returning the hash length of the last IPCP in the list instead of the length of the actual hash. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/irmd/ipcp.c | 3 ++- src/irmd/main.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index d7abe15d..5a9a79d3 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -107,7 +107,8 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t pid, free(sock_path); len = ipcp_msg__get_packed_size(msg); - if (len == 0) { + if (len == 0 || len >= SOCK_BUF_SIZE) { + log_warn("IPCP message has invalid size: %zd.", len); close(sockfd); return NULL; } diff --git a/src/irmd/main.c b/src/irmd/main.c index 6e1a1262..bc13fa7c 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -970,9 +970,7 @@ static int get_ipcp_by_dst(const char * dst, type = ipcps[i]->type; algo = ipcps[i]->hash_algo; - hash->len = hash_len(algo); - - tmp = ipcps[i]->pid; + tmp = ipcps[i]->pid; enrolled = strcmp(ipcps[i]->layer, "Not enrolled.") != 0; @@ -984,6 +982,7 @@ static int get_ipcp_by_dst(const char * dst, if (err == 0 /* solution found */ || !enrolled) continue; + hash->len = hash_len(algo); hash->data = malloc(hash->len); if (hash->data == NULL) { log_warn("Failed to malloc hash for query."); -- cgit v1.2.3