From uspoerlein@gmail.com  Mon Nov 19 17:15:58 2007
Return-Path: <uspoerlein@gmail.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E620C16A418
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 Nov 2007 17:15:57 +0000 (UTC)
	(envelope-from uspoerlein@gmail.com)
Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.190])
	by mx1.freebsd.org (Postfix) with ESMTP id 761EF13C447
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 Nov 2007 17:15:57 +0000 (UTC)
	(envelope-from uspoerlein@gmail.com)
Received: by nf-out-0910.google.com with SMTP id b2so1478481nfb
        for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 Nov 2007 09:15:45 -0800 (PST)
Received: by 10.86.80.5 with SMTP id d5mr5206498fgb.1195490920965;
        Mon, 19 Nov 2007 08:48:40 -0800 (PST)
Received: from coyote.spoerlein.net ( [85.180.161.178])
        by mx.google.com with ESMTPS id l19sm7159342fgb.2007.11.19.08.48.40
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 19 Nov 2007 08:48:40 -0800 (PST)
Received: from coyote.spoerlein.net (localhost [127.0.0.1])
	by coyote.spoerlein.net (8.14.1/8.13.8) with ESMTP id lAJGmceu037969;
	Mon, 19 Nov 2007 17:48:38 +0100 (CET)
	(envelope-from q@coyote.spoerlein.net)
Received: (from q@localhost)
	by coyote.spoerlein.net (8.14.1/8.13.8/Submit) id lAJGmcrD037968;
	Mon, 19 Nov 2007 17:48:38 +0100 (CET)
	(envelope-from q)
Message-Id: <200711191648.lAJGmcrD037968@coyote.spoerlein.net>
Date: Mon, 19 Nov 2007 17:48:38 +0100 (CET)
From: Ulrich Spoerlein <uspoerlein@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] pax(1): broken -s handling of \1, \2 ...
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         118132
>Category:       bin
>Synopsis:       [patch] pax(1): broken -s handling of \1, \2 ...
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    uqs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 19 17:20:02 UTC 2007
>Closed-Date:    Fri Jun 11 16:24:27 UTC 2010
>Last-Modified:  Fri Jun 11 16:24:27 UTC 2010
>Originator:     Ulrich Spoerlein
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
1822direkt.com
>Environment:
>Description:
I was using pax(1) on RHEL 4 to be able to transform filenames upon extraction, this breaks
under FreeBSD (and at least Ubuntu 7.04, too)
>How-To-Repeat:
% mkdir foo
% touch foo/bar_baz
% echo foo/bar_baz|pax -rw -s ',^[^/]*/\(.*\)_baz$,\1,gp' /tmp
pax: Replacement name error foo/bar_baz
>Fix:
I stole the patch from the Debian bugtracker:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=451361

After recompile:
% echo foo/bar_baz | /usr/obj/usr/src/bin/pax/pax -rw -s ',^[^/]*/\(.*\)_baz$,\1,gp' /tmp
foo/bar_baz >> bar

This should be reported upstream, but I couldn't find a definitive source for our pax(1).
Someone should test this on other *BSDs, too.

--- pax.diff begins here ---
--- bin/pax/pat_rep.c.orig	Mon Nov 19 17:37:11 2007
+++ bin/pax/pat_rep.c	Mon Nov 19 17:38:39 2007
@@ -76,7 +76,7 @@
 #ifdef NET2_REGEX
 static int resub(regexp *, char *, char *, char *);
 #else
-static int resub(regex_t *, regmatch_t *, char *, char *, char *);
+static int resub(regex_t *, regmatch_t *, char *, char *, char *, char *);
 #endif
 
 /*
@@ -929,7 +929,7 @@
 #			ifdef NET2_REGEX
 			if ((res = resub(pt->rcmp,pt->nstr,outpt,endpt)) < 0) {
 #			else
-			if ((res = resub(&(pt->rcmp),pm,pt->nstr,outpt,endpt))
+			if ((res = resub(&(pt->rcmp),pm,inpt,pt->nstr,outpt,endpt))
 			    < 0) {
 #			endif
 				if (prnt)
@@ -1071,7 +1071,7 @@
  */
 
 static int
-resub(regex_t *rp, regmatch_t *pm, char *src, char *dest,
+resub(regex_t *rp, regmatch_t *pm, char *orig, char *src, char *dest,
 	char *destend)
 {
 	char *spt;
@@ -1121,7 +1121,7 @@
 		 */
 		if (len > (destend - dpt))
 			len = destend - dpt;
-		if (l_strncpy(dpt, src + pmpt->rm_so, len) != len)
+		if (l_strncpy(dpt, orig + pmpt->rm_so, len) != len)
 			return(-1);
 		dpt += len;
 	}
--- pax.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->uqs 
Responsible-Changed-By: uqs 
Responsible-Changed-When: Thu Feb 4 08:20:35 UTC 2010 
Responsible-Changed-Why:  
Grab my own PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=118132 

From: Zahemszky =?ISO-8859-2?Q?G=E1bor?= <Gabor@Zahemszky.HU>
To: uqs@FreeBSD.org, bug-followup@FreeBSD.org, uspoerlein@gmail.com
Cc:  
Subject: Re: bin/118132: [patch] pax(1): broken -s handling of \1,\2 ...
Date: Fri, 21 May 2010 00:12:28 +0200

 Hi!
 
 Yesterday I tried to use the pax utility's -s option:
 
 pax -rw -s /.*/X&Y/' lo.txt /tmp/
 
 but got a "Replacement name error .." message. Made some testing, and
 found, that it's totally broken. I'd like to send-pr about it, but
 before it, I searched the FreeBSD gnats db. I found your bugreport (and
 the patch in it) :=20
 http://www.freebsd.org/cgi/query-pr.cgi?pr=3Dbin/118132
 
 I tried the patch, and it works for me, too. I use FreeBSD 8.0-RELEASE,
 both x86 and amd64 versions, and pax was wrong on both of them (and
 works with the patch)
 
 My question is: will you close this bug, and will you backport it to
 8-stable? (I'd like to use that feature of pax in the not so far 8.1R)
 - it's a 2 and a half year open bug ...
 
 Thanks,
 
 G=E1bor < Gabor at Zahemszky dot HU >
 
 --=20
 #!/bin/ksh
 #
 # See my GPG key at http://www.Zahemszky.HU
 #
 Z=3D'21N16I25C25E30, 40M30E33E25T15U!';
 IFS=3D' ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
 set -- $Z;for i;{ [[ $i =3D ? ]]&&print $i&&break;
 [[ $i =3D ??? ]]&&j=3D$i&&i=3D${i%?};
 typeset -i40 i=3D8#$i;print -n ${i#???};
 [[ "$j" =3D ??? ]]&&print -n "${j#??} "&&j=3D;typeset +i i;};
 IFS=3D' 0123456789 ';set -- $Z;for i;{ [[ $i =3D , ]]&&i=3D2;
 [[ $i =3D ?? ]]||typeset -l i;j=3D"$j $i";typeset +l i;};print "$j"
State-Changed-From-To: open->patched 
State-Changed-By: uqs 
State-Changed-When: Mon May 24 06:33:48 UTC 2010 
State-Changed-Why:  
Patched in HEAD r208484, going to MFC in about three weeks 

http://www.freebsd.org/cgi/query-pr.cgi?pr=118132 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/118132: commit references a PR
Date: Mon, 24 May 2010 06:33:25 +0000 (UTC)

 Author: uqs
 Date: Mon May 24 06:33:14 2010
 New Revision: 208484
 URL: http://svn.freebsd.org/changeset/base/208484
 
 Log:
   Fix back references in substitute command for pax(1)
   
   pax(1) was trying to copy the back-referenced data from
   the match pattern, not the matched data.
   
   PR:		bin/118132
   Obtained from:	Debian bug #451361
   Reviewed by:	jilles
   MFC after:	3 weeks
 
 Modified:
   head/bin/pax/pat_rep.c
 
 Modified: head/bin/pax/pat_rep.c
 ==============================================================================
 --- head/bin/pax/pat_rep.c	Mon May 24 06:26:38 2010	(r208483)
 +++ head/bin/pax/pat_rep.c	Mon May 24 06:33:14 2010	(r208484)
 @@ -76,7 +76,7 @@ static char * range_match(char *, int);
  #ifdef NET2_REGEX
  static int resub(regexp *, char *, char *, char *);
  #else
 -static int resub(regex_t *, regmatch_t *, char *, char *, char *);
 +static int resub(regex_t *, regmatch_t *, char *, char *, char *, char *);
  #endif
  
  /*
 @@ -929,7 +929,7 @@ rep_name(char *name, int *nlen, int prnt
  #			ifdef NET2_REGEX
  			if ((res = resub(pt->rcmp,pt->nstr,outpt,endpt)) < 0) {
  #			else
 -			if ((res = resub(&(pt->rcmp),pm,pt->nstr,outpt,endpt))
 +			if ((res = resub(&(pt->rcmp),pm,inpt,pt->nstr,outpt,endpt))
  			    < 0) {
  #			endif
  				if (prnt)
 @@ -1071,7 +1071,7 @@ resub(regexp *prog, char *src, char *des
   */
  
  static int
 -resub(regex_t *rp, regmatch_t *pm, char *src, char *dest,
 +resub(regex_t *rp, regmatch_t *pm, char *orig, char *src, char *dest,
  	char *destend)
  {
  	char *spt;
 @@ -1121,7 +1121,7 @@ resub(regex_t *rp, regmatch_t *pm, char 
  		 */
  		if (len > (destend - dpt))
  			len = destend - dpt;
 -		if (l_strncpy(dpt, src + pmpt->rm_so, len) != len)
 +		if (l_strncpy(dpt, orig + pmpt->rm_so, len) != len)
  			return(-1);
  		dpt += len;
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: uqs 
State-Changed-When: Fri Jun 11 16:24:10 UTC 2010 
State-Changed-Why:  
Merged to RELENG_8 

http://www.freebsd.org/cgi/query-pr.cgi?pr=118132 
>Unformatted:
