From: Paul Eggert Date: Fri, 16 Dec 2016 17:34:02 +0000 (-0800) Subject: regex: fix integer-overflow bug in never-used code X-Git-Tag: v1.0~6492 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ea7015f681a96287ebb7315f897ee1474b0ffbe9;p=gnulib.git regex: fix integer-overflow bug in never-used code Problem reported by Clément Pit–Claudel in: http://lists.gnu.org/archive/html/emacs-devel/2016-12/msg00654.html * lib/regex_internal.h: Include intprops.h. * lib/regexec.c (re_search_2_stub): Use it to avoid undefined behavior on integer overflow. * modules/regex (Depends-on): Add intprops. --- diff --git a/ChangeLog b/ChangeLog index dd67dba44e..c588296342 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2016-12-16 Paul Eggert + regex: fix integer-overflow bug in never-used code + Problem reported by Clément Pit–Claudel in: + http://lists.gnu.org/archive/html/emacs-devel/2016-12/msg00654.html + * lib/regex_internal.h: Include intprops.h. + * lib/regexec.c (re_search_2_stub): Use it to avoid undefined + behavior on integer overflow. + * modules/regex (Depends-on): Add intprops. + fpending: fix port to MinGW on Emacs * lib/stdio-impl.h [__MINGW32__]: Do not include errno.h. Problem reported by Eli Zaretskii in: diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 56a315a4f7..7ac5f92671 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -33,6 +33,8 @@ #include #include +#include "intprops.h" + #ifdef _LIBC # include # define lock_define(name) __libc_lock_define (, name) diff --git a/lib/regexec.c b/lib/regexec.c index afdc1737b8..f1e61afc41 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -354,10 +354,12 @@ re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1, { const char *str; regoff_t rval; - Idx len = length1 + length2; + Idx len; char *s = NULL; - if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0)) + if (BE ((length1 < 0 || length2 < 0 || stop < 0 + || INT_ADD_WRAPV (length1, length2, &len)), + 0)) return -2; /* Concatenate the strings. */ diff --git a/modules/regex b/modules/regex index c5ae1b255f..e1c9b5887b 100644 --- a/modules/regex +++ b/modules/regex @@ -18,6 +18,7 @@ ssize_t alloca-opt [test $ac_use_included_regex = yes] btowc [test $ac_use_included_regex = yes] gettext-h [test $ac_use_included_regex = yes] +intprops [test $ac_use_included_regex = yes] lock [test "$ac_cv_gnu_library_2_1:$ac_use_included_regex" = no:yes] memcmp [test $ac_use_included_regex = yes] memmove [test $ac_use_included_regex = yes]