Skip to content

Commit

Permalink
btrbk: remove double-slash from file arguments
Browse files Browse the repository at this point in the history
Sanitize file (or subvolume path) arguments in safe_cmd, effectively
removing leading double slash.

Files originating from "volume /" can be assembled as "//some/subvol",
which is useful internally but undesired as command arguments, as
ancient systems might interpret leading double slash "//" in a special
way.

Posix states:

> A pathname that begins with two successive slashes may be
> interpreted in an implementation-defined manner, although more than
> two leading slashes shall be treated as a single slash.
  • Loading branch information
digint committed Dec 2, 2022
1 parent c0d6a41 commit 142fa6c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions btrbk
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,12 @@ sub _safe_cmd($;$)
$_ = $_->{unsafe};
die "cannot quote leading dash for command: $_" if(/^-/);
# NOTE: all files must be absolute
if($offending) {
push @$offending, $_ unless(defined(check_file($_, { absolute => 1 })));
my $file = check_file($_, { absolute => 1 }, sanitize => 1 );
unless(defined($file)) {
die "uncaught unsafe file: $_" unless($offending);
push @$offending, $_;
}
$_ = $prefix . quoteshell($_) . $postfix;
$_ = $prefix . quoteshell($file // $_) . $postfix;
}
$_
} @$aref;
Expand Down

0 comments on commit 142fa6c

Please sign in to comment.