Package: pax
Version: 1:1.5-15
Severity: important
Tags: patch

Hi ya

$ touch foobar
$ echo foobar | pax -rwds '/.*/&&/P' .
pax: Replacement name error foobar

This is because the resub() function that does the replacement,
upon a '&', attempts to copy data from the _pattern_ string
(above: ".*") instead of the input data "foobar". So, above, it
tries to copy 6 bytes (as in "foobar") from ".*" and obviously
fails.

Here is a patch:

diff -pur pax-1.5.orig/pat_rep.c pax-1.5/pat_rep.c
--- pax-1.5.orig/pat_rep.c      1998-12-03 04:35:52.000000000 +0000
+++ pax-1.5/pat_rep.c   2007-11-15 11:02:19.729489995 +0000
@@ -85,7 +85,7 @@ static char * range_match __P((register 
 #ifdef NET2_REGEX
 static int resub __P((regexp *, char *, char *, register char *));
 #else
-static int resub __P((regex_t *, regmatch_t *, char *, char *, char *));
+static int resub __P((regex_t *, regmatch_t *, char *, char *, char *, char 
*));
 #endif
 
 /*
@@ -1020,7 +1020,7 @@ rep_name(name, nlen, 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)
@@ -1172,7 +1172,7 @@ resub(prog, src, dest, destend)
 
 #ifdef __STDC__
 static int
-resub(regex_t *rp, register regmatch_t *pm, char *src, char *dest,
+resub(regex_t *rp, register regmatch_t *pm, char *orig, char *src, char *dest,
        register char *destend)
 #else
 static int
@@ -1231,7 +1231,7 @@ resub(rp, pm, src, dest, destend)
                 */
                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;
        }
-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.23.1 (SMP w/2 CPU cores)
Locale: LANG=en_GB.ISO-8859-15, LC_CTYPE=en_GB.ISO-8859-15 (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages pax depends on:
ii  libc6                         2.6.1-6    GNU C Library: Shared libraries

pax recommends no packages.

-- no debconf information
diff -pur pax-1.5.orig/pat_rep.c pax-1.5/pat_rep.c
--- pax-1.5.orig/pat_rep.c	1998-12-03 04:35:52.000000000 +0000
+++ pax-1.5/pat_rep.c	2007-11-15 11:02:19.729489995 +0000
@@ -85,7 +85,7 @@ static char * range_match __P((register 
 #ifdef NET2_REGEX
 static int resub __P((regexp *, char *, char *, register char *));
 #else
-static int resub __P((regex_t *, regmatch_t *, char *, char *, char *));
+static int resub __P((regex_t *, regmatch_t *, char *, char *, char *, char *));
 #endif
 
 /*
@@ -1020,7 +1020,7 @@ rep_name(name, nlen, 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)
@@ -1172,7 +1172,7 @@ resub(prog, src, dest, destend)
 
 #ifdef __STDC__
 static int
-resub(regex_t *rp, register regmatch_t *pm, char *src, char *dest,
+resub(regex_t *rp, register regmatch_t *pm, char *orig, char *src, char *dest,
 	register char *destend)
 #else
 static int
@@ -1231,7 +1231,7 @@ resub(rp, pm, src, dest, destend)
 		 */
 		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;
 	}

Reply via email to