From 52f4d6f7b72de7308b4200b5c4b6c3ccddf617a3 Mon Sep 17 00:00:00 2001
From: Dimitri Staessens <dimitri@ouroboros.rocks>
Date: Mon, 19 Feb 2024 12:54:07 +0100
Subject: irmd: Fix free of uninitialized ptr

The reg_list_ipcps function left *ipcps uninitialized when there were
no IPCPs in the system. This caused a free to SEGV in the IRMd when
trying to allocate a flow.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
---
 src/irmd/reg/reg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/irmd/reg/reg.c b/src/irmd/reg/reg.c
index 29d2a7ba..f486c1cc 100644
--- a/src/irmd/reg/reg.c
+++ b/src/irmd/reg/reg.c
@@ -911,8 +911,10 @@ int reg_list_ipcps(ipcp_list_msg_t *** ipcps)
 
         pthread_mutex_lock(&reg.mtx);
 
-        if (reg.n_ipcps == 0)
+        if (reg.n_ipcps == 0) {
+                *ipcps = NULL;
                 goto finish;
+        }
 
         *ipcps = malloc(reg.n_ipcps * sizeof(**ipcps));
         if (*ipcps == NULL) {
@@ -2158,4 +2160,3 @@ int reg_respond_ipcp(const struct ipcp_info * info)
         pthread_mutex_unlock(&reg.mtx);
         return -EIPCP;
 }
-
-- 
cgit v1.2.3