]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix handling of ~ within the target of a 'tar -s' directive.
authorColin Percival <cperciva@daemonology.net>
Sat, 20 Aug 2011 07:19:41 +0000 (03:19 -0400)
committerColin Percival <cperciva@daemonology.net>
Sat, 20 Aug 2011 07:19:41 +0000 (03:19 -0400)
According to the man page, "~ is substituted with the match", but prior to
this commit it was substituted with the entire source string up to the end
of the matching region.

-s /o/_~/, prior to this commit: foo -> f_foo
-s /o/_~/, after this commit: foo -> f_oo

Reported by: Carlo Teubner

SVN-Revision: 3643

tar/subst.c

index 05ec42b7b19038dad6c1091c2106d79d3b0c0b8f..b73e78c420037c54d4d5ac072ac4996bc94d8fbd 100644 (file)
@@ -215,7 +215,9 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
                for (i = 0, j = 0; rule->result[i] != '\0'; ++i) {
                        if (rule->result[i] == '~') {
                                realloc_strncat(result, rule->result + j, i - j);
-                               realloc_strncat(result, name, matches[0].rm_eo);
+                               realloc_strncat(result,
+                                   name + matches[0].rm_so,
+                                   matches[0].rm_eo - matches[0].rm_so);
                                j = i + 1;
                                continue;
                        }