]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
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)
committerAurelien Jarno <aurelien@aurel32.net>
Tue, 6 Jul 2021 19:04:00 +0000 (21:04 +0200)
Use strtoul instead of atoi so that overflow can be detected.

(cherry picked from commit 5adda61f62b77384718b4c0d8336ade8f2b4b35c)

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

index f93a546d7eef9ac62353a0182660009f03dec7ee..9df02dbbb3ae58b70f6680f4efc4ed367a690c53 100644 (file)
@@ -183,6 +183,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 bcbe96e48dfc825b2891dc10dbecfd5a8ddfd5fe..1f3b09f721bbee5c0376ad2756576a65eca9fef7 100644 (file)
@@ -1399,7 +1399,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. */