From c509ca06d44934454527eb3f0843c780073bf60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Mon, 2 Nov 2026 17:44:15 +0000
Subject: [PATCH] seq: fix handling of locale decimal point and upper case hex
floats
* src/seq.c (scan_arg): Search for the locale decimal point.
Also handle uppercase 'P' in hex format floats.
(main): Recognize locale decimal point in apparent options.
* tests/seq/seq-locale.sh: Add test cases.
* NEWS: Mention the bug fix.
Discovered by Anthropic's OSS Scanner, as bug ANT-2026-ERV7HOGN.
---
NEWS | 7 +++++++
src/seq.c | 27 ++++++++++++++++++++++-----
tests/seq/seq-locale.sh | 25 ++++++++++++++++++++++++-
3 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index 22df2eb9d..6b4ed1d7b 100644
--- a/NEWS
+++ b/NEWS
@@ -134,6 +134,13 @@ GNU coreutils NEWS -*- outline -*-
For example with 'seq -w 1e40 1e40' or 'seq 1 1e-40 1'.
[This bug was present in "the beginning".]
+ 'seq' no longer treats operands using the decimal point of the current locale
+ like "0,5", or hexadecimal operands with an upper case exponent like "0x1P-1",
+ as integers. Previously 'seq 1,5 3' would output 2 and 3, and with
+ coreutils-8.32 or later 'seq 0 0,5 2' would output 0 indefinitely.
+ Also negative operands like "-,5" are no longer treated as options.
+ [bugs introduced in coreutils-8.24 and coreutils-8.31]
+
'sort --compress-program=PROG' no longer treats an unset PATH environment
variable as equivalent to a PATH environment variable defined to an empty
string. On typical platforms, that would result in PROG being executed from
diff --git a/src/seq.c b/src/seq.c
index acae21fd0..961e057eb 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -51,6 +51,9 @@
/* True if the locale settings were honored. */
static bool locale_ok;
+/* The locale's decimal point, or "." if it is empty. */
+static char const *locale_point;
+
/* If true print all number with equal width. */
static bool equal_width;
@@ -179,9 +182,17 @@ scan_arg (char const *arg)
ret.width = 0;
ret.precision = INT_MAX;
- /* Use no precision (and possibly fast generation) for integers. */
+ /* Like cl_strtold, accept '.' or the current locale's decimal point. */
char const *decimal_point = strchr (arg, '.');
- if (! decimal_point && ! strchr (arg, 'p') /* not a hex float */)
+ idx_t decimal_point_len = 1;
+ if (! decimal_point)
+ {
+ decimal_point = strstr (arg, locale_point);
+ decimal_point_len = strlen (locale_point);
+ }
+
+ /* Use no precision (and possibly fast generation) for integers. */
+ if (! decimal_point && ! strpbrk (arg, "pP") /* not a hex float */)
ret.precision = 0;
/* auto set width and precision for decimal inputs. */
@@ -192,9 +203,11 @@ scan_arg (char const *arg)
if (decimal_point)
{
- fraction_len = strcspn (decimal_point + 1, "eE");
+ fraction_len = strcspn (decimal_point + decimal_point_len, "eE");
if (fraction_len <= INT_MAX)
ret.precision = fraction_len;
+ /* printf counts a multi-byte decimal point as a single column. */
+ ret.width -= decimal_point_len - 1;
ret.width += (fraction_len == 0 /* #. -> # */
? -1
: (decimal_point == arg /* .# -> 0.# */
@@ -215,7 +228,7 @@ scan_arg (char const *arg)
{
if (decimal_point)
{
- if (e == decimal_point + 1) /* undo #. -> # above */
+ if (fraction_len == 0) /* undo #. -> # above */
ret.width++;
}
else
@@ -565,6 +578,9 @@ main (int argc, char **argv)
initialize_main (&argc, &argv);
set_program_name (argv[0]);
locale_ok = !!setlocale (LC_ALL, "");
+ locale_point = localeconv ()->decimal_point;
+ if (! *locale_point)
+ locale_point = ".";
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -577,7 +593,8 @@ main (int argc, char **argv)
{
int optc;
if (argv[optind][0] == '-'
- && ((optc = argv[optind][1]) == '.' || c_isdigit (optc)))
+ && ((optc = argv[optind][1]) == '.' || c_isdigit (optc)
+ || STRPREFIX (&argv[optind][1], locale_point)))
{
/* means negative number */
break;
diff --git a/tests/seq/seq-locale.sh b/tests/seq/seq-locale.sh
index 76cee7882..8a4beecb5 100755
--- a/tests/seq/seq-locale.sh
+++ b/tests/seq/seq-locale.sh
@@ -17,7 +17,7 @@
# along with this program. If not, see