View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012173 | GNUnet | util library | public | 2026-11-18 10:22 | 2026-11-18 11:33 |
| 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 | ||||
| Summary | 0012173: GNUNET_CONFIGURATION_get_value_float leaves the thread in the C locale when the value is malformed | ||||
| Description | Since 0009369, GNUNET_CONFIGURATION_get_value_float switches the thread to a "C" LC_NUMERIC locale with uselocale() around sscanf, but on a malformed value it returns GNUNET_SYSERR before switching back. From then on the calling thread formats and parses numbers in the C locale, whatever the program's locale is. Neither it nor GNUNET_CONFIGURATION_set_value_float calls freelocale(). glibc returns a static object for a plain "C" locale, so this only leaks with other C libraries. 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 Reproduce | setlocale (LC_ALL, "de_DE.UTF-8"); printf ("%.1f\n", 1.5); prints 1,5 GNUNET_CONFIGURATION_set_value_string (cfg, "a", "bad", "x"); GNUNET_CONFIGURATION_get_value_float (cfg, "a", "bad", &f); GNUNET_SYSERR printf ("%.1f\n", 1.5); prints 1.5 | ||||
| Additional Information | The attached patch restores the locale on every path and frees the locale objects. Its test checks that uselocale ((locale_t) 0) is unchanged after a failed parse, so it does not need any installed locale. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 0007-util-restore-the-locale-when-parsing-a-float-option-.patch (4,280 bytes)
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
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-18 10:22 | bot-cg | New Issue | |
| 2026-11-18 10:22 | bot-cg | Relationship added | child of 0012167 |
| 2026-11-18 10:23 | bot-cg | File Added: 0007-util-restore-the-locale-when-parsing-a-float-option-.patch | |
| 2026-11-18 11:07 | schanzen | Assigned To | => schanzen |
| 2026-11-18 11:07 | schanzen | Status | new => assigned |
| 2026-11-18 11:08 | schanzen | Target Version | => 0.30.0 |
| 2026-11-18 11:33 | schanzen | Status | assigned => resolved |
| 2026-11-18 11:33 | schanzen | Resolution | open => fixed |
| 2026-11-18 11:33 | schanzen | Note Added: 0030571 |