freebsd-dev/lib/libc/regex
Jessica Clarke 0aa8b18bc9 libc: Fix regexec when sizeof(char *) > sizeof(long)
The states macro is the type for engine.c to use, with states1 being a
local macro for regexec to use to determine whether it can use the small
matcher or not (by comparing nstates and 8*sizeof(states1)). However,
macro bodies are expanded in the context of their use, and so when
regexec uses states1 it uses the current value of states, which is left
over as char * from the large version (or, really, the multi-byte one,
but that reuses large's states). For all supported architectures in
FreeBSD, the two have the same size, and so this confusion is harmless.
However, for architectures like CHERI where that is not the case (or
Windows's LLP64 as discovered by LLVM and fixed in 2010 in 2e071faed8e2)
and sizeof(char *) is bigger than sizeof(long) regexec will erroneously
try to use the small matcher when nstates is between sizeof(long) and
sizeof(char *) (i.e. between 64 and 128 on CHERI, or 32 and 64 on LLP64)
and end up overflowing the number of bits in the underlying long if it
ever uses those high states. On weirder architectures where sizeof(long)
is greater than sizeof(char *) this also fixes it to not fall back on
the large matcher prematurely, but such architectures are likely limited
to the embedded space, if they exist at all.

Fix this by swapping round states and states1, so that states1 is
defined directly as being long and states is an alias for it for the
small matcher case.

Found by:	CHERI
2021-12-23 16:38:10 +00:00
..
grot
cname.h General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
COPYRIGHT
engine.c libregex: implement \b and \B (word boundary, not word boundary) 2020-12-05 03:16:05 +00:00
Makefile.inc Add libregex, connect it to the build 2018-01-22 02:44:41 +00:00
re_format.7 Remove SVR4 (System V Release 4) binary compatibility support. 2017-02-28 05:14:42 +00:00
regcomp.c libc: regex: rework unsafe pointer arithmetic 2021-01-08 13:58:35 -06:00
regerror.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
regex2.h libc: regex: retire internal EMPTBR ("Empty branch present") 2020-12-05 03:18:48 +00:00
regex.3 regex(3): belatedly document REG_POSIX from r363734 2020-08-04 02:06:49 +00:00
regexec.c libc: Fix regexec when sizeof(char *) > sizeof(long) 2021-12-23 16:38:10 +00:00
regfree.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
Symbol.map regex(3): Interpret many escaped ordinary characters as EESCAPE 2020-07-29 23:21:56 +00:00
utils.h regcomp: reduce size of bitmap for multibyte locales 2018-12-12 04:23:00 +00:00
WHATSNEW