]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: fix --debug buffer overrun
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Jan 2025 17:20:45 +0000 (09:20 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Jan 2025 17:21:42 +0000 (09:21 -0800)
* src/sort.c (debug_key): Fix undefined behavior when a key ends
before it starts.  Problem reported by Bruno Haible
<https://bugs.gnu.org/75606>.

src/sort.c

index 997566240d338d9e6ed1ad0ce982850fd2dcaccb..0928fd57c0f6096af384e7613f93a7d288338170 100644 (file)
@@ -2373,7 +2373,11 @@ debug_key (struct line const *line, struct keyfield const *key)
       if (key->sword != SIZE_MAX)
         beg = begfield (line, key);
       if (key->eword != SIZE_MAX)
-        lim = limfield (line, key);
+        {
+          lim = limfield (line, key);
+          /* Treat field ends before field starts as empty fields.  */
+          lim = MAX (beg, lim);
+        }
 
       if ((key->skipsblanks && key->sword == SIZE_MAX)
           || key->month || key_numeric (key))