]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge pull request #3088 from mostynb/improve_bsdtar_subst_error_messages
authorDustin L. Howett <dustin@howett.net>
Fri, 29 May 2026 18:48:14 +0000 (13:48 -0500)
committerMartin Matuska <martin@matuska.de>
Tue, 23 Jun 2026 08:56:22 +0000 (10:56 +0200)
tar: Improve -s Invalid replacement string error messages
(cherry picked from commit 6a8af66e641f2c9c4ae5daa3ec31427b57b4e1aa)

tar/subst.c

index 53497ad0d1a36ef0ca69fcf7507a6f27e5b713bb..6acf8cd15f31c6a7bf43573911baf4909facd9ee 100644 (file)
@@ -75,11 +75,14 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
                subst->last_rule->next = rule;
        subst->last_rule = rule;
 
-       if (*rule_text == '\0')
+       const char delim = *rule_text;
+       if (delim == '\0')
                lafe_errc(1, 0, "Empty replacement string");
-       end_pattern = strchr(rule_text + 1, *rule_text);
+       end_pattern = strchr(rule_text + 1, delim);
        if (end_pattern == NULL)
-               lafe_errc(1, 0, "Invalid replacement string");
+               lafe_errc(1, 0, "Invalid replacement string \"%s\": "
+                   "missing closing delimiter '%c' after pattern",
+                   rule_text, delim);
 
        pattern = malloc(end_pattern - rule_text);
        if (pattern == NULL)
@@ -95,9 +98,11 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
        free(pattern);
 
        start_subst = end_pattern + 1;
-       end_pattern = strchr(start_subst, *rule_text);
+       end_pattern = strchr(start_subst, delim);
        if (end_pattern == NULL)
-               lafe_errc(1, 0, "Invalid replacement string");
+               lafe_errc(1, 0, "Invalid replacement string \"%s\": "
+                   "missing closing delimiter '%c' after replacement",
+                   rule_text, delim);
 
        rule->result = malloc(end_pattern - start_subst + 1);
        if (rule->result == NULL)