btrbk: use substitutions in printf

Avoid possible interpreted sequence from values (e.g. from FILE).
pull/504/merge
Axel Burri 2022-11-20 15:57:23 +01:00
parent b800d1bb10
commit f9c7a47b6a
1 changed files with 4 additions and 2 deletions

6
btrbk
View File

@ -2092,14 +2092,16 @@ sub system_write_raw_info($$;@)
# sort by %raw_info_sort, then by key
my @line = $append ? () : ("#btrbk-v$VERSION", "# Do not edit this file");
my @subst;
push @line, '#t=' . time;
foreach(sort { (($raw_info_sort{$a} // 99) <=> ($raw_info_sort{$b} // 99)) || ($a cmp $b) } keys %$raw_info) {
push @line, ($_ . '=' . $raw_info->{$_});
push @line, ($_ . '=%s');
push @subst, $raw_info->{$_};
}
DEBUG "Writing (" . ($append ? "append:" . join(",", keys %$raw_info) : "create") . ") raw info file: $info_file";
my $ret = run_cmd(
{ cmd => [ 'printf', quoteshell(join('\n', @line) . '\n') ] },
{ cmd => [ 'printf', quoteshell(join('\n', @line, "")), map quoteshell($_), @subst ] },
{ ($append ? "append_to_file" : "redirect_to_file") => { unsafe => $info_file },
rsh => vinfo_rsh($vol),
});