From 2ecac103b938f39f30d76c44b4216384dc90834c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 18 Nov 2026 11:16:43 +0100 Subject: [PATCH 3/7] util: skip inaccessible sections when serializing Pass 1 of GNUNET_CONFIGURATION_serialize leaves out sections whose @inline-secret@ file could not be read, but pass 2 still wrote their headers, overflowing the buffer. Fixes #12170 Assisted by LLM --- src/lib/util/configuration.c | 3 ++ src/lib/util/test_configuration.c | 48 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c index b16f4ccaa..8e318d192 100644 --- a/src/lib/util/configuration.c +++ b/src/lib/util/configuration.c @@ -1329,6 +1329,9 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, { int len; + /* skipped in pass 1 */ + if (sec->inaccessible && (NULL == sec->entries)) + continue; len = GNUNET_asprintf (&cbuf, "[%s]\n", sec->name); diff --git a/src/lib/util/test_configuration.c b/src/lib/util/test_configuration.c index 28087ab05..6303026fa 100644 --- a/src/lib/util/test_configuration.c +++ b/src/lib/util/test_configuration.c @@ -1061,6 +1061,53 @@ testExpandRecursive (void) } +/** + * Test serializing a configuration with a section whose + * \@inline-secret\@ file cannot be read. + */ +static int +testSerializeInaccessible (void) +{ + static const char data[] = + "[a]\n" + "X = 1\n" + "@inline-secret@ secret /nonexistent/gnunet-test-secret.conf\n"; + struct GNUNET_CONFIGURATION_Handle *scfg; + char *mem; + size_t size; + int ret = 0; + + scfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ()); + if (GNUNET_OK != + GNUNET_CONFIGURATION_deserialize (scfg, + data, + strlen (data), + "test_configuration_data.conf")) + { + GNUNET_break (0); + GNUNET_CONFIGURATION_destroy (scfg); + return 1; + } + mem = GNUNET_CONFIGURATION_serialize (scfg, + &size); + if ( (NULL != memmem (mem, + size, + "[secret]", + strlen ("[secret]"))) || + (NULL == memmem (mem, + size, + "X = 1", + strlen ("X = 1"))) ) + { + GNUNET_break (0); + ret = 1; + } + GNUNET_free (mem); + GNUNET_CONFIGURATION_destroy (scfg); + return ret; +} + + int main (int argc, char *argv[]) { @@ -1073,6 +1120,7 @@ main (int argc, char *argv[]) failureCount += testClean (); failureCount += testExpandEmpty (); failureCount += testExpandRecursive (); + failureCount += testSerializeInaccessible (); if (failureCount > 0) goto error; -- 2.47.3