File: Dpkg_Source_Patch.t

package info (click to toggle)
dpkg 1.15.11
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,212 kB
  • ctags: 3,725
  • sloc: ansic: 23,363; perl: 13,947; sh: 6,860; cpp: 4,545; makefile: 996; lex: 209; sed: 16
file content (70 lines) | stat: -rw-r--r-- 2,508 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

use strict;
use warnings;

use Test::More tests => 9;

use File::Path qw(make_path);

BEGIN {
    use_ok('Dpkg::Source::Patch');
}

my $srcdir = $ENV{srcdir} || '.';
my $datadir = $srcdir . '/t/Dpkg_Source_Patch';
my $tmpdir = 't.tmp/Dpkg_Source_Patch';

sub test_patch_escape {
    my ($name, $symlink, $patchname, $desc) = @_;

    make_path("$tmpdir/$name-tree");
    make_path("$tmpdir/$name-out");
    symlink "../$name-out", "$tmpdir/$name-tree/$symlink";

    my $patch = Dpkg::Source::Patch->new(filename => "$datadir/$patchname");
    eval {
        $patch->apply("$tmpdir/$name-tree", verbose => 0);
    };
    ok(rmdir "$tmpdir/$name-out", $desc);
}

# This is CVE-2014-0471 with GNU patch >= 2.7
test_patch_escape('c-style-parsed', "\tmp", 'c-style.patch',
                  'Patch cannot escape using known c-style encoded filename');

# This is CVE-2014-0471 with GNU patch < 2.7
test_patch_escape('c-style-unknown', '\\tmp', 'c-style.patch',
                  'Patch cannot escape using unknown c-style encoded filename');

# This is CVE-2014-3865
test_patch_escape('index-alone', 'symlink', 'index-alone.patch',
                  'Patch cannot escape using Index: w/o ---/+++ header');
test_patch_escape('index-+++', 'symlink', 'index-+++.patch',
                  'Patch cannot escape using Index: w/ only +++ header');
test_patch_escape('index-inert', 'symlink', 'index-inert.patch',
                  'Patch should not fail to apply using an inert Index:');
ok(-e "$tmpdir/index-inert-tree/inert-file",
   'Patch with inert Index: applies correrctly');

# This is CVE-2014-3864
test_patch_escape('partial', 'symlink', 'partial.patch',
                  'Patch cannot escape using partial +++ header');

test_patch_escape('ghost-hunk', 'symlink', 'ghost-hunk.patch',
                  'Patch cannot escape using a disabling hunk');

1;