View Issue Details

IDProjectCategoryView StatusLast Update
0012170GNUnetutil librarypublic2026-11-18 11:27
Reporterbot-cg [agent] Assigned Toschanzen  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Product VersionGit master 
Target Version0.30.0Fixed in Version0.30.0 
Summary0012170: GNUNET_CONFIGURATION_serialize overflows its buffer for a section whose @inline-secret@ file cannot be read
DescriptionPass 1 of GNUNET_CONFIGURATION_serialize skips sections that are inaccessible and have no entries (the section of an @inline-secret@ directive whose file could not be read) when it computes the buffer size, but pass 2 still writes "[name]\n" and "\n" for them. That writes past the end of the buffer, and then GNUNET_assert (c_size == m_size) at configuration.c:1368 aborts.

GNUNET_CONFIGURATION_write serializes, and so does nat_auto_api.c on the configuration it is given, so an ordinary configuration that uses @inline-secret@ for a file the process may not read is enough. gnunet-config does not trigger it, because it writes a GNUNET_CONFIGURATION_dup, which drops such sections.

Found while testing a Go implementation of the GNUnet/Taler configuration format differentially against libgnunetutil at 57a93edc3. A patch with a regression test is attached; it is one of the series described in the parent issue.
Steps To Reproduceprintf '[a]\nX = 1\n@inline-secret@ sec missing-secret.conf\n' > s.conf

  cfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ());
  GNUNET_CONFIGURATION_parse (cfg, "s.conf");
  mem = GNUNET_CONFIGURATION_serialize (cfg, &size);

under valgrind:
  Invalid write of size 2 at memmove, by GNUNET_CONFIGURATION_serialize (configuration.c:1336)
  Address ... is 0 bytes after a block of size 20 alloc'd (configuration.c:1323)
  ERROR Assertion failed at ../src/lib/util/configuration.c:1368. Aborting.
Additional InformationThe attached patch makes pass 2 skip the same sections as pass 1.
TagsNo tags attached.
Attached Files
0003-util-skip-inaccessible-sections-when-serializing.patch (2,967 bytes)   
From 2ecac103b938f39f30d76c44b4216384dc90834c Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
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

Relationships

child of 0012167 resolvedschanzen configuration parsing: six bugs found by differential testing (patch series attached) 

Activities

schanzen

2026-11-18 11:27

manager   ~0030569

Applied as 336561149c2df07b205d4b1d065b2e9247ec8d67

Issue History

Date ModifiedUsernameFieldChange
2026-11-18 10:22bot-cgNew Issue
2026-11-18 10:22bot-cgRelationship addedchild of 0012167
2026-11-18 10:23bot-cgFile Added: 0003-util-skip-inaccessible-sections-when-serializing.patch
2026-11-18 11:05schanzenAssigned To => schanzen
2026-11-18 11:05schanzenStatusnew => assigned
2026-11-18 11:06schanzenTarget Version => 0.30.0
2026-11-18 11:27schanzenStatusassigned => resolved
2026-11-18 11:27schanzenResolutionopen => fixed
2026-11-18 11:27schanzenFixed in Version => 0.30.0
2026-11-18 11:27schanzenNote Added: 0030569