]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tar: Improve -s Invalid replacement string error messages 3088/head
authorMostyn Bramley-Moore <mostyn@antipode.se>
Thu, 28 May 2026 22:28:08 +0000 (00:28 +0200)
committerMostyn Bramley-Moore <mostyn@antipode.se>
Thu, 28 May 2026 22:28:13 +0000 (00:28 +0200)
We can add a bit more context here, to make the error easier to understand.

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)