While less version 444 included the vast majority of the "searching input that contains NUL" diff that was passed around years ago, there was one bit that was lost along the way: use of REG_STARTEND. regexec(3) implmentations that support the non-standard REG_STARTEND aren't limited to searching NUL-terminated strings, but rather can search length-delimited strings. Without the diff below, regexp matches that occur after a NUL in the input being viewed won't match.
I've already forwarded this diff to <[email protected]> for possible inclusion in the primary less(1) source tree, but I think it makes sense to commit it to OpenBSD sooner, as I doubt I'm the only one affected by this. For an illustration, try this: printf 'foo\0bar\n' > /tmp/f less +/foo /tmp/f less +/bar /tmp/f The first 'less' call will match just fine, but the second will fail to match until you rebuild with this diff. oks? Philip Guenther Index: pattern.c =================================================================== RCS file: /cvs/src/usr.bin/less/pattern.c,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 pattern.c --- pattern.c 16 Sep 2011 17:47:07 -0000 1.1.1.1 +++ pattern.c 3 Aug 2013 08:48:22 -0000 @@ -260,6 +260,11 @@ match_pattern(pattern, tpattern, line, l { regmatch_t rm; int flags = (notbol) ? REG_NOTBOL : 0; +#ifdef REG_STARTEND + flags |= REG_STARTEND; + rm.rm_so = 0; + rm.rm_eo = line_len; +#endif matched = !regexec(spattern, line, 1, &rm, flags); if (matched) {
