>From 01ec92af9fda3163f3379d5932991b47f011aa33 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 8 Mar 2019 19:17:37 +0100 Subject: [PATCH 1/4] unictype/numeric: Fix undefined behaviour. Reported by Jeffrey Walton . * 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. --- ChangeLog | 10 ++++++++++ lib/unictype/bidi_of.c | 2 +- lib/unictype/categ_of.c | 2 +- lib/unictype/joininggroup_of.c | 2 +- lib/unictype/numeric.c | 4 ++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5ba157..2e61261 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2019-03-08 Bruno Haible + + unictype/numeric: Fix undefined behaviour. + Reported by Jeffrey Walton . + * 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 git-version-gen: fix --version copyright year diff --git a/lib/unictype/bidi_of.c b/lib/unictype/bidi_of.c index 7e52117..3db1f3a 100644 --- a/lib/unictype/bidi_of.c +++ b/lib/unictype/bidi_of.c @@ -39,7 +39,7 @@ uc_bidi_class (ucs4_t uc) 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; diff --git a/lib/unictype/categ_of.c b/lib/unictype/categ_of.c index a1e6762..4c3f127 100644 --- a/lib/unictype/categ_of.c +++ b/lib/unictype/categ_of.c @@ -39,7 +39,7 @@ lookup_withtable (ucs4_t uc) 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; diff --git a/lib/unictype/joininggroup_of.c b/lib/unictype/joininggroup_of.c index db254a9..3b2a75e 100644 --- a/lib/unictype/joininggroup_of.c +++ b/lib/unictype/joininggroup_of.c @@ -39,7 +39,7 @@ uc_joining_group (ucs4_t uc) 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; diff --git a/lib/unictype/numeric.c b/lib/unictype/numeric.c index fd6eab9..a999183 100644 --- a/lib/unictype/numeric.c +++ b/lib/unictype/numeric.c @@ -39,8 +39,8 @@ uc_numeric_value (ucs4_t uc) 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; -- 2.7.4