changeset 40210:44073ad4207f

unictype/numeric: Fix undefined behaviour. Reported by Jeffrey Walton <noloader@gmail.com>. * lib/unictype/numeric.c (uc_numeric_value): Avoid undefined behaviour on shift overflow, caught by "gcc -fsanitize=undefined". * lib/unictype/bidi_of.c (uc_bidi_class): Add cast, for clarity. * lib/unictype/categ_of.c (lookup_withtable): Likewise. * lib/unictype/joininggroup_of.c (uc_joining_group): Likewise.
author Bruno Haible <bruno@clisp.org>
date Fri, 08 Mar 2019 19:17:37 +0100
parents c43e83386661
children 5f58d2ac35ea
files ChangeLog lib/unictype/bidi_of.c lib/unictype/categ_of.c lib/unictype/joininggroup_of.c lib/unictype/numeric.c
diffstat 5 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Mar 08 09:27:47 2019 -0800
+++ b/ChangeLog	Fri Mar 08 19:17:37 2019 +0100
@@ -1,3 +1,13 @@
+2019-03-08  Bruno Haible  <bruno@clisp.org>
+
+	unictype/numeric: Fix undefined behaviour.
+	Reported by Jeffrey Walton <noloader@gmail.com>.
+	* lib/unictype/numeric.c (uc_numeric_value): Avoid undefined behaviour
+	on shift overflow, caught by "gcc -fsanitize=undefined".
+	* lib/unictype/bidi_of.c (uc_bidi_class): Add cast, for clarity.
+	* lib/unictype/categ_of.c (lookup_withtable): Likewise.
+	* lib/unictype/joininggroup_of.c (uc_joining_group): Likewise.
+
 2019-03-05  Paul Eggert  <eggert@cs.ucla.edu>
 
 	git-version-gen: fix --version copyright year
--- a/lib/unictype/bidi_of.c	Fri Mar 08 09:27:47 2019 -0800
+++ b/lib/unictype/bidi_of.c	Fri Mar 08 19:17:37 2019 +0100
@@ -39,7 +39,7 @@
               unsigned int index3 = ((uc & bidi_category_header_4) + lookup2) * 5;
               /* level3 contains 5-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_bidi_category.level3[index3>>4]
+                (((unsigned int) u_bidi_category.level3[index3>>4]
                   | ((unsigned int) u_bidi_category.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x1f;
--- a/lib/unictype/categ_of.c	Fri Mar 08 09:27:47 2019 -0800
+++ b/lib/unictype/categ_of.c	Fri Mar 08 19:17:37 2019 +0100
@@ -39,7 +39,7 @@
               unsigned int index3 = ((uc & category_header_4) + lookup2) * 5;
               /* level3 contains 5-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_category.level3[index3>>4]
+                (((unsigned int) u_category.level3[index3>>4]
                   | ((unsigned int) u_category.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x1f;
--- a/lib/unictype/joininggroup_of.c	Fri Mar 08 09:27:47 2019 -0800
+++ b/lib/unictype/joininggroup_of.c	Fri Mar 08 19:17:37 2019 +0100
@@ -39,7 +39,7 @@
               unsigned int index3 = ((uc & joining_group_header_4) + lookup2) * 7;
               /* level3 contains 7-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_joining_group.level3[index3>>4]
+                (((unsigned int) u_joining_group.level3[index3>>4]
                   | ((unsigned int) u_joining_group.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x7f;
--- a/lib/unictype/numeric.c	Fri Mar 08 09:27:47 2019 -0800
+++ b/lib/unictype/numeric.c	Fri Mar 08 19:17:37 2019 +0100
@@ -39,8 +39,8 @@
               unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 8;
               /* level3 contains 8-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_numeric.level3[index3>>4]
-                  | (u_numeric.level3[(index3>>4)+1] << 16))
+                (((unsigned int) u_numeric.level3[index3>>4]
+                  | ((unsigned int) u_numeric.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0xff;