bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/6] uniname/uniname-tests: integer overflow fix


From: Paul Eggert
Subject: [PATCH 6/6] uniname/uniname-tests: integer overflow fix
Date: Mon, 25 Sep 2017 18:29:13 -0700

* tests/uniname/test-uninames.c (fill_names, fill_aliases):
Check for integer overflow.
---
 ChangeLog                     |  4 ++++
 tests/uniname/test-uninames.c | 12 ++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c1bf07eff..4585cf12b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2017-09-25  Paul Eggert  <address@hidden>
 
+       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 dfa2c4230..476bb07f0 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)
         {
-- 
2.13.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]