Bug 184632

Summary: textproc/sgmlformat: broken regexp -> regex conversion
Product: Ports & Packages Reporter: Christian Weisgerber <naddy>
Component: Individual Port(s)Assignee: Jun Kuriyama <kuriyama>
Status: Closed FIXED    
Severity: Affects Only Me CC: robak
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Christian Weisgerber freebsd_committer freebsd_triage 2013-12-09 15:00:00 UTC
I don't know how to test this functionality, but the conversion
from UNIX V8 <regexp.h> to POSIX <regex.h> in patch-regex.txt cannot
possibly be correct.

You may want to compare the regex(3) and old regexp(3) man pages.
http://svnweb.freebsd.org/base/stable/8/lib/libcompat/regexp/regexp.3?revision=196045&view=markup

The most obvious problem is in translate.c, where changes like this
 
-               if (!regexec(t->attpair[a].rex, atval)) match = 0;
+               if (!regexec(&t->attpair[a].rex, atval, 0, NULL, 0)) match = 0;
 
ignore that V8 regexec() and POSIX regexec() have inverted result
codes.  V8 regexec() returns 0 for failure, POSIX regexec() returns
0 for success.

The problems in traninit.c are more subtle:

-       if (!(T.var_RE_value=regcomp(buf)))     {
+       if (regcomp(&T.var_RE_value, buf, 0) != 0) {

What happens in the error case?  When POSIX regcomp() returns an
error, the value of var_RE_value will be undefined.  However, in
translate.c, regexec() is blindly called with this value.

Also, V8 regcomp() uses extended regular expressions.

I have attached a replacement patch that reimplements the conversion
from regexp to regex.  It uses two simple wrapper functions that
map the required V8 regcomp/regexec functionality onto POSIX
regcomp/regexec.  In particular, this allows us to still use
(regex_t *)NULL to indicate an invalid/nonexistent regular expression.

Again, I can't actually test this.
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2013-12-09 15:00:09 UTC
Responsible Changed
From-To: freebsd-ports-bugs->kuriyama

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 commit-hook freebsd_committer freebsd_triage 2015-03-14 10:28:01 UTC
A commit references this bug:

Author: robak
Date: Sat Mar 14 10:27:55 UTC 2015
New revision: 381256
URL: https://svnweb.freebsd.org/changeset/ports/381256

Log:
  textproc/sgmlformat: fix broken regexp -> regex conversion

  - Maintainer's timeout (kuriyama@FreeBSD.org)

  PR:		184632
  Submitted by:	Christian Weisgerber <naddy@FreeBSD.org>

Changes:
  head/textproc/sgmlformat/Makefile
  head/textproc/sgmlformat/files/patch-regex.txt
Comment 3 Bartek Rutkowski freebsd_committer freebsd_triage 2015-03-14 10:36:14 UTC
Committed, thanks for your work!