History log of /openbsd-current/lib/libc/regex/engine.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.26 28-Dec-2020 millert

Fix an off-by-one error in the marking of the O_CH operator following
an OOR2 operator. Also includes a regress test for the issue.
From FreeBSD via miod@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.25 11-Jul-2018 martijn

Drop a const-bomb on regexec. It's probably not a good idea to remove a
const promise when processing it in the regex engine.

Minor tweak and OK schwarze@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.24 21-Sep-2016 guenther

Delete casts to off_t and size_t that are implied by assignments
or prototypes. Ditto for some of the char* and void* casts too.

verified no change to instructions on ILP32 (i386) and LP64 (amd64)
ok natano@ abluhm@ deraadt@ millert@


Revision tags: OPENBSD_6_0_BASE
# 1.23 26-May-2016 martijn

Change the way regexec handles REG_STARTEND combined with REG_NOTBOL.
The new code sees this combination as a continuation of string at offset
pmatch[0].rm_so, instead of a new string which starts at that offset.
This change fixes a search quirk in vi and is needed for upcoming fixes in
ed/sed/vi.

This new behaviour is also used in gnu regex.

Lots of help from schwarze@
Manpage bits by schwarze@
OK schwarze@ and millert@


# 1.22 25-May-2016 schwarze

KNF with respect to indentation; no code change


# 1.21 25-May-2016 schwarze

Fix another one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and the
regular expression is anchored with [[:<:]] or \< _and_ uses backreferences.

Simplify the logic while here, already looking at the previous character
if REG_STARTEND and REG_NOTBOL are both in use, in anticipation of
martijn@'s upcoming patch which will further improve REG_STARTEND.

OK millert@ martijn@
Also tested by Pedro Giffuni (pfg) on FreeBSD.


# 1.20 17-May-2016 schwarze

Fix a one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and
the regular expression is anchored with ^ _and_ uses backreferences.
The segfault could only be triggered when the ^ anchor was inside
a leading () subexpression quantified with *.

OK martijn@
Patch also proofread by Pedro Giffuni <pfg at FreeBSD dot org>.


Revision tags: OPENBSD_5_9_BASE
# 1.19 28-Dec-2015 mmcc

Remove NULL-checks before free() and needless argument casts.

ok tb@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.18 09-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a, b), which gives us
proper mult int overflow detection. The existing code already handles
malloc failure properly, of course.


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.17 28-Nov-2013 guenther

The print() routine here can be passed at least some of the non-characters
OUT to EOW, making its domain CHAR_MIN...CODEMAX. It makes sense to have
pchar() take the same domain and output those non-characters appropriately,
so the (unsigned char) cast for isprint() goes in pchar(). Constipate
pchar() while we're here, and let print() pass through NUL to it, as it
knows how to output it unambiguously.

ok otto@ millert@


Revision tags: OPENBSD_5_4_BASE
# 1.16 17-Apr-2013 tedu

silence some warnings by adding prototypes, casts, and headers as
appropriate. in regex, stop using the struct hack for a fixed size array


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 05-Aug-2005 espie

zap rcsid


Revision tags: OPENBSD_3_7_BASE
# 1.14 03-Jan-2005 otto

Plug a mem leak. Now you can run hanoi.sed witt a lot of pegs and not
run out of mem! From FreeBSD PR 75656.

ok millert@ deraadt@


# 1.13 30-Nov-2004 otto

remove useless comments, once used for header file generation and delete
parameter names from prototypes. ok millert@


# 1.12 29-Nov-2004 otto

Better fix for the "unbounded recursion case", for example
\(b*\)\(a*\1\)*, more cases in regress/lib/libc/regexp/test.
Only stop evaluation of a back reference if the match lenght is
zero and the recursion level is too deep. With help from jaredy@
Problem case found by Andrew Brown in NetBSD PR 28126.
ok deraadt@ millert@


# 1.11 17-Oct-2004 otto

ansify and deregister; no change in obj code. ok millert@


Revision tags: OPENBSD_3_6_BASE
# 1.10 13-Aug-2004 millert

Change an assert into a loop termination condition. Fixes a core
dump found by jmc@. OK otto@


# 1.9 02-Apr-2004 otto

Avoid unbounded recursion in some expressions involving back references.
For example:
echo "foo foo bar bar bar baz" | sed 's/\([^ ]*\)\( *\1\)*/\1/g'
Test case found by dhartmei@
ok millert@ dhartmei@ tedu@


# 1.8 30-Mar-2004 millert

Allow compilation w/ -DREDEBUG; non-debug compilation is unaffected.
From NetBSD.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 25-May-2002 deraadt

remaining easy snprintf conversions


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 28-Apr-1997 millert

- cast usages of *printf() to void since we don't check return val
- move an assert to be *before* a strcpy() where it can do some good.
- integrate NetBSD fixes for 64-bit machines (NetBSD PR #3450, Ross Harvey)
- add lite2 tags


# 1.3 12-Apr-1997 millert

long -> int to fix 64bit issues. This breaks 16bit machines but since we don't have any 16bit ports...) The alternative is to use int32_t's but then this code will break when/if int > 32bits which is not so unlikely. Fixes NetBSD PR #3450 from Ross Harvey (but in a different way)


Revision tags: OPENBSD_2_0_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.25 11-Jul-2018 martijn

Drop a const-bomb on regexec. It's probably not a good idea to remove a
const promise when processing it in the regex engine.

Minor tweak and OK schwarze@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.24 21-Sep-2016 guenther

Delete casts to off_t and size_t that are implied by assignments
or prototypes. Ditto for some of the char* and void* casts too.

verified no change to instructions on ILP32 (i386) and LP64 (amd64)
ok natano@ abluhm@ deraadt@ millert@


Revision tags: OPENBSD_6_0_BASE
# 1.23 26-May-2016 martijn

Change the way regexec handles REG_STARTEND combined with REG_NOTBOL.
The new code sees this combination as a continuation of string at offset
pmatch[0].rm_so, instead of a new string which starts at that offset.
This change fixes a search quirk in vi and is needed for upcoming fixes in
ed/sed/vi.

This new behaviour is also used in gnu regex.

Lots of help from schwarze@
Manpage bits by schwarze@
OK schwarze@ and millert@


# 1.22 25-May-2016 schwarze

KNF with respect to indentation; no code change


# 1.21 25-May-2016 schwarze

Fix another one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and the
regular expression is anchored with [[:<:]] or \< _and_ uses backreferences.

Simplify the logic while here, already looking at the previous character
if REG_STARTEND and REG_NOTBOL are both in use, in anticipation of
martijn@'s upcoming patch which will further improve REG_STARTEND.

OK millert@ martijn@
Also tested by Pedro Giffuni (pfg) on FreeBSD.


# 1.20 17-May-2016 schwarze

Fix a one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and
the regular expression is anchored with ^ _and_ uses backreferences.
The segfault could only be triggered when the ^ anchor was inside
a leading () subexpression quantified with *.

OK martijn@
Patch also proofread by Pedro Giffuni <pfg at FreeBSD dot org>.


Revision tags: OPENBSD_5_9_BASE
# 1.19 28-Dec-2015 mmcc

Remove NULL-checks before free() and needless argument casts.

ok tb@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.18 09-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a, b), which gives us
proper mult int overflow detection. The existing code already handles
malloc failure properly, of course.


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.17 28-Nov-2013 guenther

The print() routine here can be passed at least some of the non-characters
OUT to EOW, making its domain CHAR_MIN...CODEMAX. It makes sense to have
pchar() take the same domain and output those non-characters appropriately,
so the (unsigned char) cast for isprint() goes in pchar(). Constipate
pchar() while we're here, and let print() pass through NUL to it, as it
knows how to output it unambiguously.

ok otto@ millert@


Revision tags: OPENBSD_5_4_BASE
# 1.16 17-Apr-2013 tedu

silence some warnings by adding prototypes, casts, and headers as
appropriate. in regex, stop using the struct hack for a fixed size array


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 05-Aug-2005 espie

zap rcsid


Revision tags: OPENBSD_3_7_BASE
# 1.14 03-Jan-2005 otto

Plug a mem leak. Now you can run hanoi.sed witt a lot of pegs and not
run out of mem! From FreeBSD PR 75656.

ok millert@ deraadt@


# 1.13 30-Nov-2004 otto

remove useless comments, once used for header file generation and delete
parameter names from prototypes. ok millert@


# 1.12 29-Nov-2004 otto

Better fix for the "unbounded recursion case", for example
\(b*\)\(a*\1\)*, more cases in regress/lib/libc/regexp/test.
Only stop evaluation of a back reference if the match lenght is
zero and the recursion level is too deep. With help from jaredy@
Problem case found by Andrew Brown in NetBSD PR 28126.
ok deraadt@ millert@


# 1.11 17-Oct-2004 otto

ansify and deregister; no change in obj code. ok millert@


Revision tags: OPENBSD_3_6_BASE
# 1.10 13-Aug-2004 millert

Change an assert into a loop termination condition. Fixes a core
dump found by jmc@. OK otto@


# 1.9 02-Apr-2004 otto

Avoid unbounded recursion in some expressions involving back references.
For example:
echo "foo foo bar bar bar baz" | sed 's/\([^ ]*\)\( *\1\)*/\1/g'
Test case found by dhartmei@
ok millert@ dhartmei@ tedu@


# 1.8 30-Mar-2004 millert

Allow compilation w/ -DREDEBUG; non-debug compilation is unaffected.
From NetBSD.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 25-May-2002 deraadt

remaining easy snprintf conversions


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 28-Apr-1997 millert

- cast usages of *printf() to void since we don't check return val
- move an assert to be *before* a strcpy() where it can do some good.
- integrate NetBSD fixes for 64-bit machines (NetBSD PR #3450, Ross Harvey)
- add lite2 tags


# 1.3 12-Apr-1997 millert

long -> int to fix 64bit issues. This breaks 16bit machines but since we don't have any 16bit ports...) The alternative is to use int32_t's but then this code will break when/if int > 32bits which is not so unlikely. Fixes NetBSD PR #3450 from Ross Harvey (but in a different way)


Revision tags: OPENBSD_2_0_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.24 21-Sep-2016 guenther

Delete casts to off_t and size_t that are implied by assignments
or prototypes. Ditto for some of the char* and void* casts too.

verified no change to instructions on ILP32 (i386) and LP64 (amd64)
ok natano@ abluhm@ deraadt@ millert@


Revision tags: OPENBSD_6_0_BASE
# 1.23 26-May-2016 martijn

Change the way regexec handles REG_STARTEND combined with REG_NOTBOL.
The new code sees this combination as a continuation of string at offset
pmatch[0].rm_so, instead of a new string which starts at that offset.
This change fixes a search quirk in vi and is needed for upcoming fixes in
ed/sed/vi.

This new behaviour is also used in gnu regex.

Lots of help from schwarze@
Manpage bits by schwarze@
OK schwarze@ and millert@


# 1.22 25-May-2016 schwarze

KNF with respect to indentation; no code change


# 1.21 25-May-2016 schwarze

Fix another one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and the
regular expression is anchored with [[:<:]] or \< _and_ uses backreferences.

Simplify the logic while here, already looking at the previous character
if REG_STARTEND and REG_NOTBOL are both in use, in anticipation of
martijn@'s upcoming patch which will further improve REG_STARTEND.

OK millert@ martijn@
Also tested by Pedro Giffuni (pfg) on FreeBSD.


# 1.20 17-May-2016 schwarze

Fix a one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and
the regular expression is anchored with ^ _and_ uses backreferences.
The segfault could only be triggered when the ^ anchor was inside
a leading () subexpression quantified with *.

OK martijn@
Patch also proofread by Pedro Giffuni <pfg at FreeBSD dot org>.


Revision tags: OPENBSD_5_9_BASE
# 1.19 28-Dec-2015 mmcc

Remove NULL-checks before free() and needless argument casts.

ok tb@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.18 09-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a, b), which gives us
proper mult int overflow detection. The existing code already handles
malloc failure properly, of course.


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.17 28-Nov-2013 guenther

The print() routine here can be passed at least some of the non-characters
OUT to EOW, making its domain CHAR_MIN...CODEMAX. It makes sense to have
pchar() take the same domain and output those non-characters appropriately,
so the (unsigned char) cast for isprint() goes in pchar(). Constipate
pchar() while we're here, and let print() pass through NUL to it, as it
knows how to output it unambiguously.

ok otto@ millert@


Revision tags: OPENBSD_5_4_BASE
# 1.16 17-Apr-2013 tedu

silence some warnings by adding prototypes, casts, and headers as
appropriate. in regex, stop using the struct hack for a fixed size array


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 05-Aug-2005 espie

zap rcsid


Revision tags: OPENBSD_3_7_BASE
# 1.14 03-Jan-2005 otto

Plug a mem leak. Now you can run hanoi.sed witt a lot of pegs and not
run out of mem! From FreeBSD PR 75656.

ok millert@ deraadt@


# 1.13 30-Nov-2004 otto

remove useless comments, once used for header file generation and delete
parameter names from prototypes. ok millert@


# 1.12 29-Nov-2004 otto

Better fix for the "unbounded recursion case", for example
\(b*\)\(a*\1\)*, more cases in regress/lib/libc/regexp/test.
Only stop evaluation of a back reference if the match lenght is
zero and the recursion level is too deep. With help from jaredy@
Problem case found by Andrew Brown in NetBSD PR 28126.
ok deraadt@ millert@


# 1.11 17-Oct-2004 otto

ansify and deregister; no change in obj code. ok millert@


Revision tags: OPENBSD_3_6_BASE
# 1.10 13-Aug-2004 millert

Change an assert into a loop termination condition. Fixes a core
dump found by jmc@. OK otto@


# 1.9 02-Apr-2004 otto

Avoid unbounded recursion in some expressions involving back references.
For example:
echo "foo foo bar bar bar baz" | sed 's/\([^ ]*\)\( *\1\)*/\1/g'
Test case found by dhartmei@
ok millert@ dhartmei@ tedu@


# 1.8 30-Mar-2004 millert

Allow compilation w/ -DREDEBUG; non-debug compilation is unaffected.
From NetBSD.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 25-May-2002 deraadt

remaining easy snprintf conversions


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 28-Apr-1997 millert

- cast usages of *printf() to void since we don't check return val
- move an assert to be *before* a strcpy() where it can do some good.
- integrate NetBSD fixes for 64-bit machines (NetBSD PR #3450, Ross Harvey)
- add lite2 tags


# 1.3 12-Apr-1997 millert

long -> int to fix 64bit issues. This breaks 16bit machines but since we don't have any 16bit ports...) The alternative is to use int32_t's but then this code will break when/if int > 32bits which is not so unlikely. Fixes NetBSD PR #3450 from Ross Harvey (but in a different way)


Revision tags: OPENBSD_2_0_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision