From: Paul Eggert Date: Tue, 26 Sep 2017 01:26:25 +0000 (-0700) Subject: uniname/uniname-tests: integer overflow fix X-Git-Tag: v1.0~5900 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c4cf0d48e28724b3ef6f40d21d0abeaface6993c;p=gnulib.git uniname/uniname-tests: integer overflow fix * tests/uniname/test-uninames.c (fill_names, fill_aliases): Check for integer overflow. --- diff --git a/ChangeLog b/ChangeLog index c1bf07eff0..4585cf12bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-09-25 Paul Eggert + uniname/uniname-tests: integer overflow fix + * tests/uniname/test-uninames.c (fill_names, fill_aliases): + Check for integer overflow. + duplocale-tests: fix unlikely crash * tests/test-duplocale.c (get_locale_dependent_values): Don’t crash with absurdly long month names. diff --git a/tests/uniname/test-uninames.c b/tests/uniname/test-uninames.c index dfa2c4230b..476bb07f05 100644 --- a/tests/uniname/test-uninames.c +++ b/tests/uniname/test-uninames.c @@ -64,6 +64,7 @@ fill_names (const char *unicodedata_filename) char *p; char *comment; unsigned int i; + unsigned long ul; lineno++; @@ -94,12 +95,13 @@ fill_names (const char *unicodedata_filename) exit (EXIT_FAILURE); } *p = '\0'; - i = strtoul (field0, NULL, 16); - if (i >= 0x110000) + ul = strtoul (field0, NULL, 16); + if (ul >= 0x110000) { fprintf (stderr, "index too large\n"); exit (EXIT_FAILURE); } + i = ul; unicode_names[i] = xstrdup (field1); } if (ferror (stream) || fclose (stream)) @@ -132,6 +134,7 @@ fill_aliases (const char *namealiases_filename) char *p; char *comment; unsigned int uc; + unsigned long ul; comment = strchr (line, '#'); if (comment != NULL) @@ -161,12 +164,13 @@ fill_aliases (const char *namealiases_filename) } *p = '\0'; - uc = strtoul (field0, NULL, 16); - if (uc >= 0x110000) + ul = strtoul (field0, NULL, 16); + if (ul >= 0x110000) { fprintf (stderr, "index too large\n"); exit (EXIT_FAILURE); } + uc = ul; if (aliases_count == ALIASLEN) {