[PATCH] util: fix segfaults when config lacks a section

fence <[email protected]> Wed, 24 Jul 2024 18:36:22 +0200
Newsgroups gmane.network.gnunet.devel
Message-ID <[email protected]>
Hi!

I ran into gnunets services just segfaulting sometimes.

I ran into the behaviour when running the transport service with the
transport.conf from the (meson) build output. (with an additional PEER 
section for the private key).

I think I had similar segfaults with other services too, but don't feel 
like trying to reproduce those tbh.

Was the NULL check missing due to performance or something?

Kind regards
fence
0001-util-fix-segfaults-when-config-lacks-a-section.patch (text/x-diff, 923 B)
From fe5757f56f2443e1bc95ad17ab376be781752877 Mon Sep 17 00:00:00 2001
From: fence <[email protected]>
Date: Tue, 23 Jul 2024 15:33:50 +0200
Subject: [PATCH] util: fix segfaults when config lacks a section

I ran into the behaviour when running the transport service with the
transport.conf from the build output.
I think I had similar segfaults with other services too.
---
 src/lib/util/configuration.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c
index 17ba253ff..909a4e4a3 100644
--- a/src/lib/util/configuration.c
+++ b/src/lib/util/configuration.c
@@ -400,6 +400,9 @@ find_section (const struct GNUNET_CONFIGURATION_Handle *cfg,
 {
   struct ConfigSection *pos;
 
+  if (NULL == cfg)
+    return NULL;
+
   pos = cfg->sections;
   while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
     pos = pos->next;
-- 
2.39.3 (Apple Git-145)