Rebuild dpkg for 7.0.
[packages/centos6/dpkg.git] / fedora-fix-CVE-2010-0396-00.patch
1 diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm
2 --- a/scripts/Dpkg/Source/Patch.pm
3 +++ b/scripts/Dpkg/Source/Patch.pm
4 @@ -322,8 +322,9 @@ sub analyze {
5             error(_g("expected ^--- in line %d of diff `%s'"), $., $diff);
6         }
7          $_ = strip_ts($_);
8 -        if ($_ eq '/dev/null' or s{^(\./)?[^/]+/}{$destdir/}) {
9 +        if ($_ eq '/dev/null' or s{^[^/]+/}{$destdir/}) {
10              $fn = $_;
11 +           error(_g("%s contains an insecure path: %s"), $diff, $_) if m{/\.\./};
12          }
13         if (/\.dpkg-orig$/) {
14             error(_g("diff `%s' patches file with name ending .dpkg-orig"), $diff);
15 @@ -336,8 +337,9 @@ sub analyze {
16             error(_g("line after --- isn't as expected in diff `%s' (line %d)"), $diff, $.);
17         }
18          $_ = strip_ts($_);
19 -        if ($_ eq '/dev/null' or s{^(\./)?[^/]+/}{$destdir/}) {
20 +        if ($_ eq '/dev/null' or s{^[^/]+/}{$destdir/}) {
21              $fn2 = $_;
22 +           error(_g("%s contains an insecure path: %s"), $diff, $_) if m{/\.\./};
23          } else {
24              unless (defined $fn) {
25                  error(_g("none of the filenames in ---/+++ are relative in diff `%s' (line %d)"),
26 @@ -363,6 +365,17 @@ sub analyze {
27         if ($dirname =~ s{/[^/]+$}{} && not -d $dirname) {
28             $dirtocreate{$dirname} = 1;
29         }
30 +
31 +       # Sanity check, refuse to patch through a symlink
32 +       $dirname = $fn;
33 +       while (1) {
34 +           if (-l $dirname) {
35 +               error(_g("diff %s modifies file %s through a symlink: %s"),
36 +                     $diff, $fn, $dirname);
37 +           }
38 +           last unless $dirname =~ s{/[^/]+$}{};
39 +       }
40 +
41         if (-e $fn and not -f _) {
42             error(_g("diff `%s' patches something which is not a plain file"), $diff);
43         }