XPost: comp.unix.bsd.freebsd.misc
On 03/02/2022 16:39, Lew Pitcher wrote:
On Thu, 03 Feb 2022 15:52:47 +0000, Mike Scott wrote:
This is on freebsd13.0/arm64/rpi4
A problem arising from milter-regex. This fails to accept known-good
regular expressions, directly taken from a working i386 system.
I believe the problem lies in the regex library, as a test program fails
to compile regular expressions that contain backslashed special
characters:
The salient chunk of my test program is
regex_t re;
if( regcomp( &re, argv[1], REG_ICASE ) ) {
printf("bad re\n");
.....
Thanks for the responses.
Firstly, I have to confess to some history: way, way back, I modified milter-regex to use pcre rather than libc's regex routines. That's
probably why my patterns still have \s strings and the like: these are
valid in pcre as \s -> whitespace and \t -> tab etc.
That said, the "proper" package code from freebsd was reinstated several
years ago, and both systems (i386 and arm64) are running the same
packaged version 2.7.2. (It means my re's certainly haven't worked for a
while, but that's a separate issue: ooops!) I have the exact same
milter-regex config file on both machines.
On the arm64 box (fbsd 13.0), I get logged:
parse_ruleset: /usr/local/etc/milter-regex.conf:196: regcomp:
^\s*Fwd.?\s*$: trailing backslash (\)
As has been pointed out, \s may not mean what I wanted it to: but is nevertheless valid, and that re should be accepted as equivalent to
^s*Fwd.?s*$
(man re_format is unambiguous on this)
On the i386 (running fbsd 11.4), the file compiles happily in full.
Hence my supposition about errors in the regex library.
The error returned in my test code on the arm64 from regcomp() is 5 (REG_EESCAPE). On the i386 I get
% ./a '\b' '123abc4 56'
re <<\b>> string <<123abc4 56>>
matching:- <<b>>
and on the arm64:
root@kirk:/usr/plumtree/config/milter-regex # ./a '\b' '123abc4 56'
re <<\b>> string <<123abc4 56>>
bad re 5
Hmmm. I'm wondering about char's and int's. It's been a long, long while
since I looked into the depths of Henry Spencer's original code (that on
a Sun): I have a vague recollection of liberties being taken with them
but IMWBW.
FWIW the test code, hacked from elsewhere, is
#include <stdio.h>
#include <regex.h>
#include <stdlib.h>
#define MAXMATCH 100
int main(int argc, char *argv[]) {
regex_t re;
regmatch_t matches[MAXMATCH];
if( argc != 3 ) exit(1);
printf("re <<%s>> string <<%s>>\n", argv[1], argv[2]);
/* if( regcomp( &re, argv[1], REG_EXTENDED | REG_ICASE ) ) { */
int errc = regcomp( &re, argv[1], REG_ICASE );
if( errc ) {
printf("bad re %x\n", errc);
exit(1);
}
int err = regexec( &re, argv[2], MAXMATCH, matches, 0);
if( err ) {
printf("match failed %d\n", err);
exit(1);
}
printf("matching:- <<");
int p;
for( p = matches[0].rm_so; p < matches[0].rm_eo; ++p )
printf("%c", argv[2][p]);
printf(">>\n");
}
--
Mike Scott
Harlow, England
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)