diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-06-27 14:05:56 -0400 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-07-06 10:46:46 -0300 |
commit | 320ac7eeb47671e03ee26d4419b640fac0312390 (patch) | |
tree | 8de38a4597acb794997802c59e9e5bbe40c2ec80 /wcsmbs | |
parent | 5324d258427fd11ca0f4f595c94016e568b26d6b (diff) | |
download | glibc-320ac7eeb47671e03ee26d4419b640fac0312390.zip glibc-320ac7eeb47671e03ee26d4419b640fac0312390.tar.gz glibc-320ac7eeb47671e03ee26d4419b640fac0312390.tar.bz2 |
vfscanf-internal: Remove potentially unbounded allocas
Some locales define a list of mapping pairs of alternate digits and
separators for input digits (to_inpunct). This require the scanf
to create a list of all possible inputs for the optional type
modifier 'I'.
Checked on x86_64-linux-gnu.
Reviewed-by: Joe Simmons-Talbott <josimmon@redhat.com>
Diffstat (limited to 'wcsmbs')
-rw-r--r-- | wcsmbs/Makefile | 3 | ||||
-rw-r--r-- | wcsmbs/tst-wscanf-to_inpunct.c | 79 |
2 files changed, 82 insertions, 0 deletions
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile index d25a221..431136b 100644 --- a/wcsmbs/Makefile +++ b/wcsmbs/Makefile @@ -196,6 +196,7 @@ tests := \ tst-wscanf-binary-c2x \ tst-wscanf-binary-gnu11 \ tst-wscanf-binary-gnu89 \ + tst-wscanf-to_inpunct \ wcsatcliff \ wcsmbs-tst1 \ # tests @@ -207,6 +208,7 @@ LOCALES := \ de_DE.ISO-8859-1 \ de_DE.UTF-8 \ en_US.ANSI_X3.4-1968 \ + fa_IR.UTF-8 \ hr_HR.ISO-8859-2 \ ja_JP.EUC-JP \ tr_TR.ISO-8859-9 \ @@ -228,6 +230,7 @@ $(objpfx)tst-c16-surrogate.out: $(gen-locales) $(objpfx)tst-c32-state.out: $(gen-locales) $(objpfx)test-c8rtomb.out: $(gen-locales) $(objpfx)test-mbrtoc8.out: $(gen-locales) +$(objpfx)tst-wscanf-to_inpunct.out: $(gen-locales) endif $(objpfx)tst-wcstod-round: $(libm) diff --git a/wcsmbs/tst-wscanf-to_inpunct.c b/wcsmbs/tst-wscanf-to_inpunct.c new file mode 100644 index 0000000..72f2a1a --- /dev/null +++ b/wcsmbs/tst-wscanf-to_inpunct.c @@ -0,0 +1,79 @@ +/* Test scanf for languages with mapping pairs of alternate digits and + separators. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <array_length.h> +#include <stdio.h> +#include <support/support.h> +#include <support/check.h> +#include <wchar.h> + +/* fa_IR defines to_inpunct for numbers. */ +static const struct input_t +{ + int n; + const wchar_t str[5]; +} inputs[] = +{ + { 1, { 0x000006f1, L'\0' } }, + { 2, { 0x000006f2, L'\0' } }, + { 3, { 0x000006f3, L'\0' } }, + { 4, { 0x000006f4, L'\0' } }, + { 5, { 0x000006f5, L'\0' } }, + { 6, { 0x000006f6, L'\0' } }, + { 7, { 0x000006f7, L'\0' } }, + { 8, { 0x000006f8, L'\0' } }, + { 9, { 0x000006f9, L'\0' } }, + { 10, { 0x000006f1, 0x000006f0, L'\0' } }, + { 11, { 0x000006f1, 0x000006f1, L'\0' } }, + { 12, { 0x000006f1, 0x000006f2, L'\0' } }, + { 13, { 0x000006f1, 0x000006f3, L'\0' } }, + { 14, { 0x000006f1, 0x000006f4, L'\0' } }, + { 15, { 0x000006f1, 0x000006f5, L'\0' } }, + { 16, { 0x000006f1, 0x000006f6, L'\0' } }, + { 17, { 0x000006f1, 0x000006f7, L'\0' } }, + { 18, { 0x000006f1, 0x000006f8, L'\0' } }, + { 19, { 0x000006f1, 0x000006f9, L'\0' } }, + { 20, { 0x000006f2, 0x000006f0, L'\0' } }, + { 30, { 0x000006f3, 0x000006f0, L'\0' } }, + { 40, { 0x000006f4, 0x000006f0, L'\0' } }, + { 50, { 0x000006f5, 0x000006f0, L'\0' } }, + { 60, { 0x000006f6, 0x000006f0, L'\0' } }, + { 70, { 0x000006f7, 0x000006f0, L'\0' } }, + { 80, { 0x000006f8, 0x000006f0, L'\0' } }, + { 90, { 0x000006f9, 0x000006f0, L'\0' } }, + { 100, { 0x000006f1, 0x000006f0, 0x000006f0, L'\0' } }, + { 1000, { 0x000006f1, 0x000006f0, 0x000006f0, 0x000006f0, L'\0' } }, +}; + +static int +do_test (void) +{ + xsetlocale (LC_ALL, "fa_IR.UTF-8"); + + for (int i = 0; i < array_length (inputs); i++) + { + int n; + swscanf (inputs[i].str, L"%Id", &n); + TEST_COMPARE (n, inputs[i].n); + } + + return 0; +} + +#include <support/test-driver.c> |