9bb5d6
commit 5adda61f62b77384718b4c0d8336ade8f2b4b35c
9bb5d6
Author: Andreas Schwab <schwab@linux-m68k.org>
9bb5d6
Date:   Fri Jun 25 15:02:47 2021 +0200
9bb5d6
9bb5d6
    wordexp: handle overflow in positional parameter number (bug 28011)
9bb5d6
    
9bb5d6
    Use strtoul instead of atoi so that overflow can be detected.
9bb5d6
9bb5d6
diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c
9bb5d6
index cc29840355e047cc..30c1dd65efcc0b49 100644
9bb5d6
--- a/posix/wordexp-test.c
9bb5d6
+++ b/posix/wordexp-test.c
9bb5d6
@@ -200,6 +200,7 @@ struct test_case_struct
9bb5d6
     { 0, NULL, "$var", 0, 0, { NULL, }, IFS },
9bb5d6
     { 0, NULL, "\"\\n\"", 0, 1, { "\\n", }, IFS },
9bb5d6
     { 0, NULL, "", 0, 0, { NULL, }, IFS },
9bb5d6
+    { 0, NULL, "${1234567890123456789012}", 0, 0, { NULL, }, IFS },
9bb5d6
 
9bb5d6
     /* Flags not already covered (testit() has special handling for these) */
9bb5d6
     { 0, NULL, "one two", WRDE_DOOFFS, 2, { "one", "two", }, IFS },
9bb5d6
diff --git a/posix/wordexp.c b/posix/wordexp.c
9bb5d6
index 048a8068544c81fa..4061969c720f1f34 100644
9bb5d6
--- a/posix/wordexp.c
9bb5d6
+++ b/posix/wordexp.c
9bb5d6
@@ -1420,7 +1420,7 @@ envsubst:
9bb5d6
   /* Is it a numeric parameter? */
9bb5d6
   else if (isdigit (env[0]))
9bb5d6
     {
9bb5d6
-      int n = atoi (env);
9bb5d6
+      unsigned long n = strtoul (env, NULL, 10);
9bb5d6
 
9bb5d6
       if (n >= __libc_argc)
9bb5d6
 	/* Substitute NULL. */