aboutsummaryrefslogtreecommitdiff
path: root/tar/subst.c
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2024-04-11 13:37:34 +0000
committerMartin Matuska <mm@FreeBSD.org>2024-04-11 13:48:20 +0000
commita509d68f27b9f114b876bbe3b9caa9d0ee0c5606 (patch)
treedb454f3d1b46887ce3a0d48478e058a1024be892 /tar/subst.c
parenta5913a473bb0b6e194a2fe0e55d3166e0eed8aaf (diff)
downloadsrc-a509d68f27b9f114b876bbe3b9caa9d0ee0c5606.tar.gz
src-a509d68f27b9f114b876bbe3b9caa9d0ee0c5606.zip
Update vendor/libarchive to 3.7.3
New features: #1941 uudecode filter: support file name and file mode in raw mode #1943 7-zip reader: translate Windows permissions into UNIX permissions #1962 zstd filter now supports the "long" write option #2012 add trailing letter b to bsdtar(1) substitute pattern #2031 PCRE2 support #2054 add support for long options "--group" and "--owner" to tar(1) Security fixes: #2101 Fix possible vulnerability in tar error reporting introduced in f27c173 Important bugfixes: #1974 ISO9660: preserve the natural order of links #2105 rar5: fix infinite loop if during rar5 decompression the last block produced no data #2027 xz filter: fix incorrect eof at the end of an lzip member #2043 zip: fix end-of-data marker processing when decompressing zip archives Obtained from: libarchive Libarchive commit: 4fcc02d906cca4b9e21a78a833f1142a2689ec52
Diffstat (limited to 'tar/subst.c')
-rw-r--r--tar/subst.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/tar/subst.c b/tar/subst.c
index 55ad63dcecde..9747abb906c4 100644
--- a/tar/subst.c
+++ b/tar/subst.c
@@ -24,14 +24,15 @@
*/
#include "bsdtar_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/subst.c,v 1.4 2008/06/15 10:08:16 kientzle Exp $");
-#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H)
#include "bsdtar.h"
#include <errno.h>
-#ifdef HAVE_PCREPOSIX_H
+#if defined(HAVE_PCREPOSIX_H)
#include <pcreposix.h>
+#elif defined(HAVE_PCRE2POSIX_H)
+#include <pcre2posix.h>
#else
#include <regex.h>
#endif
@@ -48,7 +49,7 @@ struct subst_rule {
struct subst_rule *next;
regex_t re;
char *result;
- unsigned int global:1, print:1, regular:1, symlink:1, hardlink:1;
+ unsigned int global:1, print:1, regular:1, symlink:1, hardlink:1, from_begin:1;
};
struct substitution {
@@ -128,9 +129,14 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
rule->regular = 1; /* Rewrite regular filenames. */
rule->symlink = 1; /* Rewrite symlink targets. */
rule->hardlink = 1; /* Rewrite hardlink targets. */
+ rule->from_begin = 0; /* Don't match from start. */
while (*++end_pattern) {
switch (*end_pattern) {
+ case 'b':
+ case 'B':
+ rule->from_begin = 1;
+ break;
case 'g':
case 'G':
rule->global = 1;
@@ -159,6 +165,7 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
break;
default:
lafe_errc(1, 0, "Invalid replacement flag %c", *end_pattern);
+ /* NOTREACHED */
}
}
}
@@ -212,6 +219,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result,
{
const char *path = name;
regmatch_t matches[10];
+ char* buffer = NULL;
size_t i, j;
struct subst_rule *rule;
struct substitution *subst;
@@ -237,6 +245,13 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result,
continue;
}
+ if (rule->from_begin && *result) {
+ realloc_strcat(result, name);
+ realloc_strcat(&buffer, *result);
+ name = buffer;
+ (*result)[0] = 0;
+ }
+
while (1) {
if (regexec(&rule->re, name, 10, matches, 0))
break;
@@ -276,6 +291,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result,
case '9':
realloc_strncat(result, rule->result + j, i - j - 1);
if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) {
+ free(buffer);
free(*result);
*result = NULL;
return -1;
@@ -302,6 +318,8 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result,
if (got_match)
realloc_strcat(result, name);
+ free(buffer);
+
if (print_match)
fprintf(stderr, "%s >> %s\n", path, *result);
@@ -325,4 +343,4 @@ cleanup_substitution(struct bsdtar *bsdtar)
}
free(subst);
}
-#endif /* defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) */
+#endif /* defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H) */