Skip to content
Permalink
Browse files Browse the repository at this point in the history
[backend] sanity check the result of the external patch command
Simple files only, please.
  • Loading branch information
mlschroe committed Aug 10, 2015
1 parent d508b6e commit 474a3db
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/backend/bs_srcserver
Expand Up @@ -1979,10 +1979,28 @@ sub applylink {
die("/usr/bin/patch: $!\n");
}
waitpid($pid, 0) == $pid || die("waitpid $pid: $!\n");
if ($?) {
$failed = "could not apply patch '$pn'";
last;
$failed = "could not apply patch '$pn'" if $?;
# clean up patch fallout...
for my $f (ls($tmpdir)) {
my @s = lstat("$tmpdir/$f");
die("$tmpdir/$f: $!\n") unless @s;
if (-l _ || ! -f _) {
unlink("$tmpdir/$f");
$failed = "patch created a non-file";
next;
}
eval {
die("cannot create a link from a patch") if $f eq '_link';
BSVerify::verify_filename($f) unless $f eq '.log';
};
if ($@) {
unlink("$tmpdir/$f");
$failed = "patch created an illegal file";
next;
}
chmod(($s[2] & 077) | 0600, "$tmpdir/$f") if ($s[2] & 07700) != 0600;
}
last if $failed;
}
if ($failed) {
local *F;
Expand Down

0 comments on commit 474a3db

Please sign in to comment.