View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012167 | GNUnet | util library | public | 2026-11-18 10:22 | 2026-11-18 11:42 |
| Reporter | bot-cg [agent] | Assigned To | schanzen | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | Git master | ||||
| Target Version | 0.30.0 | Fixed in Version | 0.30.0 | ||
| Summary | 0012167: configuration parsing: six bugs found by differential testing (patch series attached) | ||||
| Description | While writing a Go implementation of the GNUnet/Taler configuration format, I compared it against libgnunetutil at 57a93edc3 on a corpus of edge cases and on all exchange and merchant configuration files. That turned up the bugs in the child issues, plus the already reported 0008889 (a trailing '*' in GNUNET_DISK_glob patterns), which also lets "a*c" match "a" when a longer name was scanned before it; I added the details and a patch there. Each child issue has a patch with a regression test. The seven patches form a series against 57a93edc3: they touch neighbouring code and tests, so apply them in order. The whole series is attached here as one mbox. 1. util: continue $-expansion after the expanded term 2. util: stop $-expansion at definitions that refer to themselves 3. util: skip inaccessible sections when serializing 4. util: let a final '*' in GNUNET_DISK_glob patterns match (0008889) 5. util: use the stripped line length when parsing configurations 6. util: fix the factors of the TB, PB and EB size units 7. util: restore the locale when parsing a float option fails | ||||
| Additional Information | With the series applied, the util test suite passes (51 ok, 1 skipped: test_os_start_process), the new tests pass under valgrind, and each new test fails or crashes without its fix. On the 97 configuration files in the exchange and merchant source trees, loaded on top of taler-exchange's config.d, every value, every $-expanded filename and the serialization are the same as without the series. Behaviour changes beyond the crashes: patch 1 expands a '$' that directly follows a term that expanded to ""; patch 4 makes patterns ending in '*' match; patch 5 accepts section headers with surrounding whitespace and CRLF files; patch 6 makes TB, PB and EB powers of 1000. | ||||
| Tags | No tags attached. | ||||
| Attached Files | configuration-fixes-series.mbox (31,860 bytes)
From 678fb43239dd345ee3911feda237a1b4bcfa67ae Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:15:15 +0100
Subject: [PATCH 1/7] util: continue $-expansion after the expanded term
GNUNET_CONFIGURATION_expand_dollar always resumed one character after the
start of a term, so it read past the end of the string when the last term
expanded to "", and skipped a '$' right after a term that expanded to "".
Fixes #12168
Assisted by LLM
---
src/lib/util/configuration.c | 24 ++++++++++---
src/lib/util/test_configuration.c | 56 +++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 4 deletions(-)
diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c
index 3afd8c3e4..7ecf76044 100644
--- a/src/lib/util/configuration.c
+++ b/src/lib/util/configuration.c
@@ -2693,12 +2693,16 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @param cfg configuration to use for path expansion
* @param orig string to $-expand (will be freed!)
* @param depth recursion depth, used to detect recursive expansions
+ * @param[out] skip set to the length of the expanded term at the start
+ * of the result, or to 1 if the term was not expanded, so that the
+ * caller can continue after it
* @return $-expanded string, never NULL unless @a orig was NULL
*/
static char *
expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *orig,
- unsigned int depth)
+ unsigned int depth,
+ size_t *skip)
{
char *prefix;
char *result;
@@ -2711,7 +2715,9 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
char erased_char;
char *erased_pos;
size_t len;
+ size_t def_skip;
+ *skip = 1;
if (NULL == orig)
return NULL;
if (depth > 128)
@@ -2814,7 +2820,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
/* try default */
def = expand_dollar (cfg,
def,
- depth + 1);
+ depth + 1,
+ &def_skip);
env = def;
}
if (NULL == env)
@@ -2840,6 +2847,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
prefix[len - 1] = erased_char;
prefix[len] = '\0';
}
+ *skip = strlen (prefix);
result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
strcpy (result, prefix);
strcat (result, post);
@@ -2858,18 +2866,26 @@ GNUNET_CONFIGURATION_expand_dollar (
char *dup;
size_t i;
size_t len;
+ size_t skip;
- for (i = 0; '\0' != orig[i]; i++)
+ i = 0;
+ while ('\0' != orig[i])
{
if ('$' != orig[i])
+ {
+ i++;
continue;
+ }
dup = GNUNET_strdup (orig + i);
- dup = expand_dollar (cfg, dup, 0);
+ dup = expand_dollar (cfg, dup, 0, &skip);
GNUNET_assert (NULL != dup); /* make compiler happy */
len = strlen (dup) + 1;
orig = GNUNET_realloc (orig, i + len);
GNUNET_memcpy (orig + i, dup, len);
GNUNET_free (dup);
+ /* The expansion is final; continue right after it, which may well be
+ the end of the string or another '$' if it expanded to "". */
+ i += skip;
}
return orig;
}
diff --git a/src/lib/util/test_configuration.c b/src/lib/util/test_configuration.c
index 0d86b886a..12067a91f 100644
--- a/src/lib/util/test_configuration.c
+++ b/src/lib/util/test_configuration.c
@@ -960,6 +960,61 @@ testConfigFilenames ()
}
+/**
+ * Check one $-expansion.
+ */
+static int
+check_expansion (const struct GNUNET_CONFIGURATION_Handle *ecfg,
+ const char *in,
+ const char *want)
+{
+ char *out = GNUNET_CONFIGURATION_expand_dollar (ecfg,
+ GNUNET_strdup (in));
+ int ret = 0;
+
+ if (0 != strcmp (out,
+ want))
+ {
+ fprintf (stderr,
+ "Expanding `%s' gave `%s', wanted `%s'\n",
+ in,
+ out,
+ want);
+ ret = 1;
+ }
+ GNUNET_free (out);
+ return ret;
+}
+
+
+/**
+ * Test $-expansion of terms that expand to the empty string.
+ */
+static int
+testExpandEmpty (void)
+{
+ struct GNUNET_CONFIGURATION_Handle *ecfg;
+ int ret = 0;
+
+ ecfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ());
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "EMPTY",
+ "");
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "B",
+ "/b");
+ ret += check_expansion (ecfg, "abc${EMPTY}", "abc");
+ ret += check_expansion (ecfg, "$EMPTY", "");
+ ret += check_expansion (ecfg, "${EMPTY}$B", "/b");
+ ret += check_expansion (ecfg, "x${EMPTY}${EMPTY}y$B/z", "xy/b/z");
+ ret += check_expansion (ecfg, "$NOT_SET_ANYWHERE/$B", "$NOT_SET_ANYWHERE//b");
+ GNUNET_CONFIGURATION_destroy (ecfg);
+ return ret;
+}
+
+
int
main (int argc, char *argv[])
{
@@ -970,6 +1025,7 @@ main (int argc, char *argv[])
failureCount += testDiagnostics ();
failureCount += testDiagnosticsInlineSecret ();
failureCount += testClean ();
+ failureCount += testExpandEmpty ();
if (failureCount > 0)
goto error;
--
2.47.3
From 9fc67be87d3a6cdebded775d4242b5b2a174b2f2 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:16:20 +0100
Subject: [PATCH 2/7] util: stop $-expansion at definitions that refer to
themselves
A [PATHS] option or environment variable whose value refers to itself,
directly or through others, recursed until the stack overflowed; the depth
limit only covered ${VAR:-default} chains.
Fixes #12169
Assisted by LLM
---
src/lib/util/configuration.c | 94 ++++++++++++++++++++++++++-----
src/lib/util/test_configuration.c | 47 ++++++++++++++++
2 files changed, 128 insertions(+), 13 deletions(-)
diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c
index 7ecf76044..b16f4ccaa 100644
--- a/src/lib/util/configuration.c
+++ b/src/lib/util/configuration.c
@@ -2680,6 +2680,30 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
+/**
+ * A [PATHS] option or environment variable whose value is being
+ * $-expanded, used to detect definitions that refer to themselves.
+ */
+struct ExpansionFrame
+{
+ /**
+ * The expansion this one is part of, or NULL.
+ */
+ const struct ExpansionFrame *parent;
+
+ /**
+ * Name of the variable whose value is being expanded.
+ */
+ const char *name;
+};
+
+
+static char *
+expand_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig,
+ const struct ExpansionFrame *frame);
+
+
/**
* Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
* where either in the "PATHS" section or the environment "FOO" is
@@ -2693,6 +2717,8 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @param cfg configuration to use for path expansion
* @param orig string to $-expand (will be freed!)
* @param depth recursion depth, used to detect recursive expansions
+ * @param frame variables whose values are being expanded, a variable
+ * among them is treated as undefined
* @param[out] skip set to the length of the expanded term at the start
* of the result, or to 1 if the term was not expanded, so that the
* caller can continue after it
@@ -2702,6 +2728,7 @@ static char *
expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *orig,
unsigned int depth,
+ const struct ExpansionFrame *frame,
size_t *skip)
{
char *prefix;
@@ -2716,6 +2743,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *erased_pos;
size_t len;
size_t def_skip;
+ bool recursive = false;
+ struct ExpansionFrame inner;
*skip = 1;
if (NULL == orig)
@@ -2809,18 +2838,35 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
start,
post,
def);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- start,
- &prefix))
+ for (const struct ExpansionFrame *pos = frame;
+ NULL != pos;
+ pos = pos->parent)
+ {
+ if (0 == strcmp (pos->name,
+ start))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "The definition of `%s' refers to itself, not expanding it\n",
+ start);
+ recursive = true;
+ break;
+ }
+ }
+ if (recursive ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "PATHS",
+ start,
+ &prefix)))
{
- if (NULL == (env = getenv (start)))
+ if (recursive ||
+ (NULL == (env = getenv (start))))
{
/* try default */
def = expand_dollar (cfg,
def,
depth + 1,
+ frame,
&def_skip);
env = def;
}
@@ -2838,8 +2884,11 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
prefix = GNUNET_strdup (env);
}
- prefix = GNUNET_CONFIGURATION_expand_dollar (cfg,
- prefix);
+ inner.parent = frame;
+ inner.name = start;
+ prefix = expand_all (cfg,
+ prefix,
+ &inner);
if ((erased_pos) && ('}' != erased_char))
{
len = strlen (prefix) + 1;
@@ -2858,10 +2907,18 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
-char *
-GNUNET_CONFIGURATION_expand_dollar (
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- char *orig)
+/**
+ * $-expand all terms in a string.
+ *
+ * @param cfg configuration to use for path expansion
+ * @param orig string to $-expand (will be freed!)
+ * @param frame variables whose values are being expanded
+ * @return $-expanded string
+ */
+static char *
+expand_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig,
+ const struct ExpansionFrame *frame)
{
char *dup;
size_t i;
@@ -2877,7 +2934,7 @@ GNUNET_CONFIGURATION_expand_dollar (
continue;
}
dup = GNUNET_strdup (orig + i);
- dup = expand_dollar (cfg, dup, 0, &skip);
+ dup = expand_dollar (cfg, dup, 0, frame, &skip);
GNUNET_assert (NULL != dup); /* make compiler happy */
len = strlen (dup) + 1;
orig = GNUNET_realloc (orig, i + len);
@@ -2891,6 +2948,17 @@ GNUNET_CONFIGURATION_expand_dollar (
}
+char *
+GNUNET_CONFIGURATION_expand_dollar (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig)
+{
+ return expand_all (cfg,
+ orig,
+ NULL);
+}
+
+
enum GNUNET_GenericReturnValue
GNUNET_CONFIGURATION_get_value_filename (
const struct GNUNET_CONFIGURATION_Handle *cfg,
diff --git a/src/lib/util/test_configuration.c b/src/lib/util/test_configuration.c
index 12067a91f..28087ab05 100644
--- a/src/lib/util/test_configuration.c
+++ b/src/lib/util/test_configuration.c
@@ -1015,6 +1015,52 @@ testExpandEmpty (void)
}
+/**
+ * Test $-expansion of definitions that refer to themselves.
+ */
+static int
+testExpandRecursive (void)
+{
+ struct GNUNET_CONFIGURATION_Handle *ecfg;
+ int ret = 0;
+
+ ecfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ());
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "SELF",
+ "$SELF/x");
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "A",
+ "$B/a");
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "B",
+ "$A/b");
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "D",
+ "${D:-dflt}/d");
+ GNUNET_CONFIGURATION_set_value_string (ecfg,
+ "PATHS",
+ "TWICE",
+ "${TWICE}:${TWICE}");
+ GNUNET_assert (0 == setenv ("GNUNET_TEST_SELF_ENV",
+ "$GNUNET_TEST_SELF_ENV/e",
+ 1));
+ ret += check_expansion (ecfg, "$SELF", "$SELF/x");
+ ret += check_expansion (ecfg, "$A", "$A/b/a");
+ ret += check_expansion (ecfg, "$D", "dflt/d");
+ ret += check_expansion (ecfg, "$TWICE", "${TWICE}:${TWICE}");
+ ret += check_expansion (ecfg,
+ "$GNUNET_TEST_SELF_ENV",
+ "$GNUNET_TEST_SELF_ENV/e");
+ GNUNET_assert (0 == unsetenv ("GNUNET_TEST_SELF_ENV"));
+ GNUNET_CONFIGURATION_destroy (ecfg);
+ return ret;
+}
+
+
int
main (int argc, char *argv[])
{
@@ -1026,6 +1072,7 @@ main (int argc, char *argv[])
failureCount += testDiagnosticsInlineSecret ();
failureCount += testClean ();
failureCount += testExpandEmpty ();
+ failureCount += testExpandRecursive ();
if (failureCount > 0)
goto error;
--
2.47.3
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
From 4023f4a23c2b341b35fa0f25186122cfbe28cf57 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:17:21 +0100
Subject: [PATCH 4/7] util: let a final '*' in GNUNET_DISK_glob patterns match
glob_match gave up once the '*' would have to swallow the last character,
so "test*" matched nothing, and it then looked one byte past the name,
which made "a*c" match "a" if a longer name had been scanned before.
Fixes #8889
Assisted by LLM
---
src/lib/util/disk.c | 5 ++-
src/lib/util/test_disk.c | 70 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 3 deletions(-)
diff --git a/src/lib/util/disk.c b/src/lib/util/disk.c
index ca924ff6c..4a6ce84bc 100644
--- a/src/lib/util/disk.c
+++ b/src/lib/util/disk.c
@@ -994,13 +994,12 @@ glob_match (const char *pattern, const char *str)
}
else
{
- if (NULL == str_bt)
+ if ( (NULL == str_bt) ||
+ ('\0' == *str_bt) )
return false;
/* Backtrack to match one more
character as part of the asterisk. */
str_pos = str_bt + 1;
- if ('\0' == *str_pos)
- return false;
pat_pos = pat_bt;
}
}
diff --git a/src/lib/util/test_disk.c b/src/lib/util/test_disk.c
index 61932d27a..ae5abae9e 100644
--- a/src/lib/util/test_disk.c
+++ b/src/lib/util/test_disk.c
@@ -276,6 +276,75 @@ testDirMani ()
}
+/**
+ * Check how many files in "test-glob" match a pattern.
+ */
+static int
+check_glob (const char *pattern,
+ int want)
+{
+ int found = 0;
+ int ret;
+
+ ret = GNUNET_DISK_glob (pattern,
+ &iter_callback,
+ &found);
+ if ( (want != ret) ||
+ (want != found) )
+ {
+ fprintf (stderr,
+ "Glob `%s' matched %d files (%d callbacks), wanted %d\n",
+ pattern,
+ ret,
+ found,
+ want);
+ return 1;
+ }
+ return 0;
+}
+
+
+static int
+testGlob ()
+{
+ static const char *files[] = {
+ "test0", "test1", "a", "abc", "a.conf", NULL
+ };
+ int ret = 0;
+
+ if (GNUNET_OK != GNUNET_DISK_directory_create ("test-glob"))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ for (unsigned int i = 0; NULL != files[i]; i++)
+ {
+ char *fn;
+
+ GNUNET_asprintf (&fn,
+ "test-glob" DIR_SEPARATOR_STR "%s",
+ files[i]);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_DISK_fn_write (fn,
+ "x",
+ 1,
+ GNUNET_DISK_PERM_USER_READ
+ | GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_free (fn);
+ }
+ ret += check_glob ("test-glob/test*", 2);
+ ret += check_glob ("test-glob/*", 5);
+ ret += check_glob ("test-glob/*.conf", 1);
+ ret += check_glob ("test-glob/a*", 3);
+ ret += check_glob ("test-glob/abc*", 1);
+ ret += check_glob ("test-glob/a*c", 1);
+ ret += check_glob ("test-glob/*b*", 1);
+ ret += check_glob ("test-glob/x*", 0);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove ("test-glob"));
+ return ret;
+}
+
+
int
main (int argc, char *argv[])
{
@@ -289,6 +358,7 @@ main (int argc, char *argv[])
failureCount += testCanonicalize ();
failureCount += testChangeOwner ();
failureCount += testDirMani ();
+ failureCount += testGlob ();
if (0 != failureCount)
{
fprintf (stderr,
--
2.47.3
From 1b8d3b2a827c47ddae8dba7f40f23e011dde09d0 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:17:52 +0100
Subject: [PATCH 5/7] util: use the stripped line length when parsing
configurations
GNUNET_CONFIGURATION_deserialize kept using the line length from before
whitespace was stripped and before GNUNET_strndup stopped at a NUL byte, so
it read and wrote out of bounds and rejected section headers with
surrounding whitespace, including CRLF line endings, which are now
accepted. A NUL byte in a line is now an error.
Fixes #12171
Assisted by LLM
---
src/lib/util/configuration.c | 9 ++++
src/lib/util/test_configuration.c | 70 +++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c
index 8e318d192..3a1d51314 100644
--- a/src/lib/util/configuration.c
+++ b/src/lib/util/configuration.c
@@ -873,6 +873,14 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
line = line_orig;
/* increment line number */
nr++;
+ if (strlen (line_orig) != line_size)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "NUL byte in line %u\n",
+ nr);
+ ret = GNUNET_SYSERR;
+ break;
+ }
/* tabs and '\r' are whitespace */
emptyline = GNUNET_YES;
for (size_t i = 0; i < line_size; i++)
@@ -897,6 +905,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
/* remove leading whitespace */
for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
;
+ line_size = strlen (line);
/* ignore comments */
if ( ('#' == line[0]) ||
diff --git a/src/lib/util/test_configuration.c b/src/lib/util/test_configuration.c
index 6303026fa..b340373de 100644
--- a/src/lib/util/test_configuration.c
+++ b/src/lib/util/test_configuration.c
@@ -1108,6 +1108,75 @@ testSerializeInaccessible (void)
}
+/**
+ * Check that a section header line in @a data is accepted.
+ */
+static int
+check_section_header (const char *data,
+ size_t size)
+{
+ struct GNUNET_CONFIGURATION_Handle *pcfg;
+ char *v = NULL;
+ int ret = 0;
+
+ pcfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ());
+ if ( (GNUNET_OK !=
+ GNUNET_CONFIGURATION_deserialize (pcfg,
+ data,
+ size,
+ NULL)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (pcfg,
+ "b",
+ "Y",
+ &v)) ||
+ (0 != strcmp (v,
+ "2")) )
+ {
+ fprintf (stderr,
+ "Failed to parse section header in `%s'\n",
+ data);
+ ret = 1;
+ }
+ GNUNET_free (v);
+ GNUNET_CONFIGURATION_destroy (pcfg);
+ return ret;
+}
+
+
+/**
+ * Test parsing lines with whitespace around section headers and with
+ * NUL bytes.
+ */
+static int
+testParseLines (void)
+{
+ static const char nul[] = "[a]\nX = 1\0\t\t\t\t\n";
+ struct GNUNET_CONFIGURATION_Handle *pcfg;
+ int ret = 0;
+
+ ret += check_section_header ("[a]\nX = 1\n [b]\nY = 2\n",
+ strlen ("[a]\nX = 1\n [b]\nY = 2\n"));
+ ret += check_section_header ("[b] \nY = 2\n",
+ strlen ("[b] \nY = 2\n"));
+ ret += check_section_header ("[b]\r\nY = 2\r\n",
+ strlen ("[b]\r\nY = 2\r\n"));
+ pcfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ());
+ if (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_deserialize (pcfg,
+ nul,
+ sizeof (nul) - 1,
+ NULL))
+ {
+ fprintf (stderr,
+ "Accepted a NUL byte in a line\n");
+ ret++;
+ }
+ GNUNET_CONFIGURATION_destroy (pcfg);
+ return ret;
+}
+
+
int
main (int argc, char *argv[])
{
@@ -1121,6 +1190,7 @@ main (int argc, char *argv[])
failureCount += testExpandEmpty ();
failureCount += testExpandRecursive ();
failureCount += testSerializeInaccessible ();
+ failureCount += testParseLines ();
if (failureCount > 0)
goto error;
--
2.47.3
From 23881fe9e236817911f6a21a256c88c5a43b55e4 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:18:13 +0100
Subject: [PATCH 6/7] util: fix the factors of the TB, PB and EB size units
They were 1000^3 * 1024 and so on, so "1 TB" was 1.024 * 10^12 bytes.
Fixes #12172
Assisted by LLM
---
src/lib/util/strings.c | 6 +++---
src/lib/util/test_strings.c | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/lib/util/strings.c b/src/lib/util/strings.c
index 947fce766..2f70b6a3c 100644
--- a/src/lib/util/strings.c
+++ b/src/lib/util/strings.c
@@ -244,11 +244,11 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
{ "GiB", 1024 * 1024 * 1024 },
{ "GB", 1000 * 1000 * 1000 },
{ "TiB", 1024LL * 1024LL * 1024LL * 1024LL },
- { "TB", 1000LL * 1000LL * 1000LL * 1024LL },
+ { "TB", 1000LL * 1000LL * 1000LL * 1000LL },
{ "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL },
- { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL },
+ { "PB", 1000LL * 1000LL * 1000LL * 1000LL * 1000LL },
{ "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL },
- { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL },
+ { "EB", 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL },
{ NULL, 0 } };
return convert_with_table (fancy_size, table, size);
diff --git a/src/lib/util/test_strings.c b/src/lib/util/test_strings.c
index 93d025612..cbf1af307 100644
--- a/src/lib/util/test_strings.c
+++ b/src/lib/util/test_strings.c
@@ -154,6 +154,28 @@ main (int argc, char *argv[])
GNUNET_STRINGS_fancy_time_to_relative ("15 m", &rtx));
GNUNET_assert (rt.rel_value_us == rtx.rel_value_us);
+ {
+ unsigned long long size;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("1 GB", &size));
+ GNUNET_assert (1000ULL * 1000ULL * 1000ULL == size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("1 TB", &size));
+ GNUNET_assert (1000ULL * 1000ULL * 1000ULL * 1000ULL == size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("2 PB", &size));
+ GNUNET_assert (2ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL ==
+ size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("3 EB", &size));
+ GNUNET_assert (3ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL
+ * 1000ULL == size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("1 TiB", &size));
+ GNUNET_assert (1ULL << 40 == size);
+ }
+
GNUNET_assert (0 != GNUNET_STRINGS_urlencode (strlen (
URLENCODE_TEST_VECTOR_PLAIN),
URLENCODE_TEST_VECTOR_PLAIN,
--
2.47.3
From e0df40536771e556475211d677dc028114b7a43c Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:18:40 +0100
Subject: [PATCH 7/7] util: restore the locale when parsing a float option
fails
GNUNET_CONFIGURATION_get_value_float returned early on a malformed value
and left the calling thread in the "C" numeric locale; neither it nor
set_value_float freed the locale object.
Fixes #12173
Assisted by LLM
---
src/lib/util/configuration.c | 25 ++++++++++------
src/lib/util/test_configuration.c | 47 +++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 8 deletions(-)
diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c
index 3a1d51314..5c119295d 100644
--- a/src/lib/util/configuration.c
+++ b/src/lib/util/configuration.c
@@ -2479,12 +2479,16 @@ GNUNET_CONFIGURATION_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg,
const locale_t cl = newlocale (LC_NUMERIC_MASK,
"C",
(locale_t) 0);
- locale_t old_locale = uselocale (cl);
+ locale_t old_locale;
+
+ GNUNET_assert ((locale_t) 0 != cl);
+ old_locale = uselocale (cl);
GNUNET_snprintf (s,
64,
"%f",
(double) number);
uselocale (old_locale);
+ freelocale (cl);
GNUNET_CONFIGURATION_set_value_string (cfg,
section,
option,
@@ -2513,14 +2517,19 @@ GNUNET_CONFIGURATION_get_value_float (
const locale_t cl = newlocale (LC_NUMERIC_MASK,
"C",
(locale_t) 0);
- locale_t old_locale = uselocale (cl);
-
- if (1 != sscanf (e->val,
- "%f%1s",
- number,
- dummy))
- return GNUNET_SYSERR;
+ locale_t old_locale;
+ int n;
+
+ GNUNET_assert ((locale_t) 0 != cl);
+ old_locale = uselocale (cl);
+ n = sscanf (e->val,
+ "%f%1s",
+ number,
+ dummy);
uselocale (old_locale);
+ freelocale (cl);
+ if (1 != n)
+ return GNUNET_SYSERR;
}
return GNUNET_OK;
}
diff --git a/src/lib/util/test_configuration.c b/src/lib/util/test_configuration.c
index b340373de..23ab25ace 100644
--- a/src/lib/util/test_configuration.c
+++ b/src/lib/util/test_configuration.c
@@ -1177,6 +1177,52 @@ testParseLines (void)
}
+/**
+ * Test that parsing a float option leaves the thread's locale alone.
+ */
+static int
+testFloatLocale (void)
+{
+ struct GNUNET_CONFIGURATION_Handle *fcfg;
+ locale_t before = uselocale ((locale_t) 0);
+ float f;
+ int ret = 0;
+
+ fcfg = GNUNET_CONFIGURATION_create (GNUNET_OS_project_data_gnunet ());
+ GNUNET_CONFIGURATION_set_value_float (fcfg,
+ "f",
+ "set",
+ 1.5f);
+ GNUNET_CONFIGURATION_set_value_string (fcfg,
+ "f",
+ "bad",
+ "1.5x");
+ if ( (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_float (fcfg,
+ "f",
+ "set",
+ &f)) ||
+ (1.5f != f) ||
+ (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_get_value_float (fcfg,
+ "f",
+ "bad",
+ &f)) )
+ {
+ GNUNET_break (0);
+ ret = 1;
+ }
+ if (before != uselocale ((locale_t) 0))
+ {
+ fprintf (stderr,
+ "Parsing a float option changed the thread's locale\n");
+ ret = 1;
+ }
+ GNUNET_CONFIGURATION_destroy (fcfg);
+ return ret;
+}
+
+
int
main (int argc, char *argv[])
{
@@ -1191,6 +1237,7 @@ main (int argc, char *argv[])
failureCount += testExpandRecursive ();
failureCount += testSerializeInaccessible ();
failureCount += testParseLines ();
+ failureCount += testFloatLocale ();
if (failureCount > 0)
goto error;
--
2.47.3
| ||||
| related to | 0008889 | resolved | schanzen | DISK_glob() not matching * at end |
| parent of | 0012168 | resolved | schanzen | GNUNET_CONFIGURATION_expand_dollar reads past the string when a $-term expands to the empty string |
| parent of | 0012169 | resolved | schanzen | GNUNET_CONFIGURATION_expand_dollar recurses until it crashes on a [PATHS] option that refers to itself |
| parent of | 0012170 | resolved | schanzen | GNUNET_CONFIGURATION_serialize overflows its buffer for a section whose @inline-secret@ file cannot be read |
| parent of | 0012171 | resolved | schanzen | GNUNET_CONFIGURATION_deserialize uses a stale line length: out-of-bounds access, and section headers with whitespace or CRLF are rejected |
| parent of | 0012172 | resolved | schanzen | GNUNET_STRINGS_fancy_size_to_bytes: TB, PB and EB are off by a factor of 1.024 |
| parent of | 0012173 | resolved | schanzen | GNUNET_CONFIGURATION_get_value_float leaves the thread in the C locale when the value is malformed |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-18 10:22 | bot-cg | New Issue | |
| 2026-11-18 10:22 | bot-cg | Relationship added | parent of 0012173 |
| 2026-11-18 10:22 | bot-cg | Relationship added | related to 0008889 |
| 2026-11-18 10:22 | bot-cg | Relationship added | parent of 0012168 |
| 2026-11-18 10:22 | bot-cg | Relationship added | parent of 0012169 |
| 2026-11-18 10:22 | bot-cg | Relationship added | parent of 0012170 |
| 2026-11-18 10:22 | bot-cg | Relationship added | parent of 0012171 |
| 2026-11-18 10:22 | bot-cg | Relationship added | parent of 0012172 |
| 2026-11-18 10:23 | bot-cg | File Added: configuration-fixes-series.mbox | |
| 2026-11-18 11:05 | schanzen | Assigned To | => schanzen |
| 2026-11-18 11:05 | schanzen | Status | new => assigned |
| 2026-11-18 11:05 | schanzen | Target Version | => 0.30.0 |
| 2026-11-18 11:42 | schanzen | Status | assigned => resolved |
| 2026-11-18 11:42 | schanzen | Resolution | open => fixed |
| 2026-11-18 11:42 | schanzen | Fixed in Version | => 0.30.0 |