[PATCH] wordexp: handle overflow in positional parameter number (bug 28011)
authorAndreas Schwab <schwab@linux-m68k.org>
Fri, 25 Jun 2021 13:02:47 +0000 (15:02 +0200)
committerAdrian Bunk <bunk@debian.org>
Sat, 29 Jun 2024 10:27:34 +0000 (13:27 +0300)
Use strtoul instead of atoi so that overflow can be detected.

Gbp-Pq: Topic all
Gbp-Pq: Name git-CVE-2021-35942-wordexp-handle-overflow-in-positional-parameter-numb.diff

posix/wordexp-test.c
posix/wordexp.c

index cc29840355e047cc68d9c0a51d6f86b8f7e9bc67..30c1dd65efcc0b49abd111b4764e124f5fc5cbaf 100644 (file)
@@ -200,6 +200,7 @@ struct test_case_struct
     { 0, NULL, "$var", 0, 0, { NULL, }, IFS },
     { 0, NULL, "\"\\n\"", 0, 1, { "\\n", }, IFS },
     { 0, NULL, "", 0, 0, { NULL, }, IFS },
+    { 0, NULL, "${1234567890123456789012}", 0, 0, { NULL, }, IFS },
 
     /* Flags not already covered (testit() has special handling for these) */
     { 0, NULL, "one two", WRDE_DOOFFS, 2, { "one", "two", }, IFS },
index 7548e0329fdeafaa9adcc9e57a68f1eae2e74b7a..d43d3e29d7747101786ab7de42681222e119fe27 100644 (file)
@@ -1419,7 +1419,7 @@ envsubst:
   /* Is it a numeric parameter? */
   else if (isdigit (env[0]))
     {
-      int n = atoi (env);
+      unsigned long n = strtoul (env, NULL, 10);
 
       if (n >= __libc_argc)
        /* Substitute NULL. */