bsdtar: fix 1-byte OOB read in substitution handling

The -s replacement scanner consumes a backslash and then reads the
escaped byte. If the replacement ends in one literal backslash, the loop
can advance past the terminating NUL and read one byte past the
allocated replacement buffer.

Stop scanning when a backslash is followed by the terminating NUL. The
final literal append then preserves the trailing backslash.
This commit is contained in:
datauwu committed 2026-07-07 21:58:54 +08:00
1 parent c16162083a
commit 0053ea743f
1 file changed
+2
+2
View File
@@ -264,6 +264,8 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result,
++i;
c = rule->result[i];
if (c == '\0')
break;
switch (c) {
case '~':
case '\\':