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