[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.12-22-g3c6abb6



The following commit has been merged in the master branch:
commit 6fd82a4aa2f8e84ad003ac01f8473bd36e36fdf6
Author: Niels Thykier <niels@thykier.net>
Date:   Sat Apr 20 18:33:41 2013 +0200

    L::Util: Rename resolve_pkg_path to normalize_pkg_path
    
    "resolve" suggests the sub does more than it did, so rename it to
    "normalize".
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/cruft b/checks/cruft
index 843c8fc..e4de909 100644
--- a/checks/cruft
+++ b/checks/cruft
@@ -36,7 +36,7 @@ use constant BLOCKSIZE => 4096;
 use Lintian::Data;
 use Lintian::Relation ();
 use Lintian::Tags qw(tag);
-use Lintian::Util qw(fail is_ancestor_of resolve_pkg_path);
+use Lintian::Util qw(fail is_ancestor_of normalize_pkg_path);
 
 use Cwd;
 use File::Find;
@@ -359,22 +359,22 @@ sub find_cruft {
     if (-l) {
         my $target = readlink($_);
         my $dirname = dirname($_);
-        my $resolved = resolve_pkg_path($dirname, $target);
-        if (not $resolved) {
+        my $normalized = normalize_pkg_path($dirname, $target);
+        if (not $normalized) {
             # skip unsafe symlinks too
             tag 'source-contains-unsafe-symlink', $_;
             return;
         }
         # This check may appear redundant, but it is not!
-        # resolve_pkg_path tells us that the link can "safely be
-        # resolved without escaping the root".  But it tells us
+        # normalized_pkg_path tells us that the link can "safely be
+        # normalized without escaping the root".  But it tells us
         # nothing about the target of the link (which could be an
         # unsafe symlink). Example
         #
         #  safe-symlink -> unsafe-symlink
         #  unsafe-symlink -> ../../../../etc/passwd
         #
-        # resolve_pkg_path would approve of "safe-symlink", but if we
+        # normalize_pkg_path would approve of "safe-symlink", but if we
         # were to open it we would actually end up escaping the
         # package root.
         if (-e and not is_ancestor_of($info->unpacked, $_)) {
diff --git a/checks/java b/checks/java
index e128efe..b669336 100644
--- a/checks/java
+++ b/checks/java
@@ -25,7 +25,7 @@ use warnings;
 use List::MoreUtils qw(any none);
 
 use Lintian::Tags qw(tag);
-use Lintian::Util qw(resolve_pkg_path);
+use Lintian::Util qw(normalize_pkg_path);
 
 sub run {
 
@@ -155,7 +155,7 @@ for my $jar_file (sort keys %{$java_info}) {
                 $p =~ s#^\./++##og;
                 if($p !~ m#^(?:file://)?/#o) {
                     if($p =~ m#/#o) {
-                        my $target = resolve_pkg_path($jar_dir, $p);
+                        my $target = normalize_pkg_path($jar_dir, $p);
                         my $tinfo;
                         # Relative link to usr/share/java ? Works if we
                         # are depending of a Java library.
diff --git a/debian/changelog b/debian/changelog
index 4dfc9cb..df1d906 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -33,6 +33,7 @@ lintian (2.5.13) UNRELEASED; urgency=low
     + [NT] Require that the input file is present for
       read_dpkg_control and get_deb_control.
     + [NT] In copy_dir, pass --reflink=auto to cp.
+    + [NT] Rename resolve_pkg_path to normalize_pkg_path.
 
   * reporting/harness:
     + [NT] Stop exporting ENV variables that lintian no longer
diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index cc76de7..c2cf2c3 100644
--- a/lib/Lintian/Collect/Package.pm
+++ b/lib/Lintian/Collect/Package.pm
@@ -27,7 +27,7 @@ use Carp qw(croak);
 use Scalar::Util qw(blessed);
 
 use Lintian::Path;
-use Lintian::Util qw(open_gz perm2oct resolve_pkg_path);
+use Lintian::Util qw(open_gz perm2oct normalize_pkg_path);
 
 =head1 NAME
 
@@ -113,7 +113,7 @@ The following code may be helpful in checking for path traversal:
     # Does not exists
  }
 
-Alternatively one can use resolve_pkg_path in L<Lintian::Util> or
+Alternatively one can use normalize_pkg_path in L<Lintian::Util> or
 L<link_resolved|Lintian::Path/link_resolved>.
 
 To get a list of entries in the package or the file meta data of the
@@ -267,7 +267,7 @@ sub _fetch_extracted_dir {
             if ($filename =~ m{(?: ^|/ ) \.\. (?: /|$ )}xsm) {
                 # possible traversal - double check it and (if needed)
                 # stop it before it gets out of hand.
-                if (resolve_pkg_path('/', $filename) eq '') {
+                if (normalize_pkg_path('/', $filename) eq '') {
                     croak qq{The path "$file" is not within the package root};
                 }
             }
diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index 3eb0d19..945e183 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -25,7 +25,7 @@ use parent qw(Class::Accessor);
 
 use Carp qw(croak);
 
-use Lintian::Util qw(resolve_pkg_path);
+use Lintian::Util qw(normalize_pkg_path);
 
 =head1 NAME
 
@@ -254,7 +254,7 @@ sub link_resolved {
     my $dir = $self->dirname;
     # hardlinks are always relative to the package root
     $dir = '/' if $self->is_hardlink;
-    my $target = resolve_pkg_path ($dir, $link);
+    my $target = normalize_pkg_path($dir, $link);
     if ($target) {
         # map "." to ''.
         $target = '' if $target eq '.';
diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index 2bb0a32..2760c87 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -73,6 +73,7 @@ BEGIN {
                  check_path
                  clean_env
                  resolve_pkg_path
+                 normalize_pkg_path
                  parse_boolean
                  is_ancestor_of
                  $PKGNAME_REGEX),
@@ -93,20 +94,20 @@ Lintian::Util - Lintian utility functions
 
 =head1 SYNOPSIS
 
- use Lintian::Util qw(slurp_entire_file resolve_pkg_path);
+ use Lintian::Util qw(slurp_entire_file normalize_pkg_path);
  
- my $text = slurp_entire_file ('some-file');
+ my $text = slurp_entire_file('some-file');
  if ($text =~ m/regex/) {
     # ...
  }
 
- my $path = resolve_pkg_path ('/usr/bin/', '../lib/git-core/git-pull');
+ my $path = normalize_pkg_path('/usr/bin/', '../lib/git-core/git-pull');
  if (-e $path) {
     # ....
  }
  
  my (@paragraphs);
- eval { @paragraphs = read_dpkg_control ('some/debian/ctrl/file'); };
+ eval { @paragraphs = read_dpkg_control('some/debian/ctrl/file'); };
  if ($@) {
     # syntax error etc.
     die "ctrl/file: $@";
@@ -1092,37 +1093,55 @@ sub check_path {
     return 0;
 }
 
-=item resolve_pkg_path (CURDIR, DEST)
+=item normalize_pkg_path(CURDIR, DEST)
 
 Using CURDIR as current directory from the (package) root,
 resolve DEST and return (the absolute) path to the destination.
 Note that the result will never start with a slash, even if
 CURDIR or DEST does. Nor will it end with a slash.
 
+As the name suggests, this is a path "normalization" rather than a
+true path resolution (for that use Cwd::realpath).  Particularly,
+it assumes none of the path segments are symlinks.
+
 Note it will return '.' if the result is the package root.
 
-Returns a non-truth value, if it cannot safely resolve the path
-(e.g. DEST would be outside the package root).
+Returns a non-truth value, if the path cannot be normalized without
+escaping the the package root.
 
 B<CAVEAT>: This function is I<not always sufficient> to test if it is
 safe to open a given symlink.  Use
 L<is_ancestor_of|Lintian::Util/is_ancestor_of(PARENTDIR, PATH)> for
 that.  If you must use this function, remember to check that the
-target is not a symlink (or if it is, that it can be resolved).
+target is not a symlink (or if it is, that it can be resolved safely).
 
 Examples:
 
-  resolve_pkg_path('/usr/share/java', '../ant/file') eq  'usr/share/ant/file'
-  resolve_pkg_path('/usr/share/java', '../../../usr/share/ant/file') eq  'usr/share/ant/file'
-  resolve_pkg_path('/', 'usr/..') eq '.';
+  normalize_pkg_path('/usr/share/java', '../ant/file') eq  'usr/share/ant/file'
+  normalize_pkg_path('/usr/share/java', '../../../usr/share/ant/file') eq  'usr/share/ant/file'
+  normalize_pkg_path('/', 'usr/..') eq '.';
 
  The following will give a non-truth result:
-  resolve_pkg_path('/usr/bin', '../../../../etc/passwd')
-  resolve_pkg_path('/usr/bin', '/../etc/passwd')
+  normalize_pkg_path('/usr/bin', '../../../../etc/passwd')
+  normalize_pkg_path('/usr/bin', '/../etc/passwd')
+
+
+The sub was named resolve_pkg_path in Lintian << 2.5.13~.
+
+=item resolve_pkg_path (CURDIR, DEST)
+
+Deprecated alias of normalize_pkg_path for << 2.5.13~.  This will go
+away in >= 2.5.14~.
 
 =cut
 
 sub resolve_pkg_path {
+    warnings::warnif('deprecated',
+                     'resolve_pkg_path was renamed to normalize_pkg_path');
+    goto \&normalize_pkg_path;
+}
+
+sub normalize_pkg_path {
     my ($curdir, $dest) = @_;
     my (@cc, @dc);
     my $target;
@@ -1136,7 +1155,7 @@ sub resolve_pkg_path {
         # absolute path, strip leading slashes and resolve
         # as relative to the root.
         $dest =~ s,^/,,o;
-        return resolve_pkg_path('/', $dest);
+        return normalize_pkg_path('/', $dest);
     }
 
     # clean up $curdir (as well)
diff --git a/t/scripts/Lintian/Util/path.t b/t/scripts/Lintian/Util/path.t
index c94205f..a481736 100644
--- a/t/scripts/Lintian/Util/path.t
+++ b/t/scripts/Lintian/Util/path.t
@@ -6,21 +6,21 @@ use Test::More tests => 12;
 
 # Lintian::Util exports fail, which clashes with Test::More, so we
 # have to be explicit about the import(s).
-BEGIN { use_ok('Lintian::Util', qw(resolve_pkg_path)); }
+BEGIN { use_ok('Lintian::Util', qw(normalize_pkg_path)); }
 
 # Safe - absolute
-is(resolve_pkg_path('/usr/share/java', '/usr/share/ant/file'), 'usr/share/ant/file', 'Safe absolute path');
-is(resolve_pkg_path('/usr/share/ant', '/'), '.', 'Safe absolute root');
+is(normalize_pkg_path('/usr/share/java', '/usr/share/ant/file'), 'usr/share/ant/file', 'Safe absolute path');
+is(normalize_pkg_path('/usr/share/ant', '/'), '.', 'Safe absolute root');
 
 # Safe - relative
-is(resolve_pkg_path('/usr/share/java', './file'), 'usr/share/java/file', 'Safe simple same-dir path');
-is(resolve_pkg_path('/usr/share/java', '../ant/file'), 'usr/share/ant/file', 'Safe simple relative path');
-is(resolve_pkg_path('/usr/share/java', '../../../usr/share/ant/file'), 'usr/share/ant/file', 'Safe absurd relative path');
-is(resolve_pkg_path('/usr/share/java', '.'), 'usr/share/java', 'Safe relative dot path');
-is(resolve_pkg_path('/', '.'), '.', 'Safe relative root dot');
-is(resolve_pkg_path('/', 'usr/..'), '.', 'Safe absurd relative root path');
-is(resolve_pkg_path('/usr/share/java', '../../../'), '.', 'Safe absurd relative path to root');
+is(normalize_pkg_path('/usr/share/java', './file'), 'usr/share/java/file', 'Safe simple same-dir path');
+is(normalize_pkg_path('/usr/share/java', '../ant/file'), 'usr/share/ant/file', 'Safe simple relative path');
+is(normalize_pkg_path('/usr/share/java', '../../../usr/share/ant/file'), 'usr/share/ant/file', 'Safe absurd relative path');
+is(normalize_pkg_path('/usr/share/java', '.'), 'usr/share/java', 'Safe relative dot path');
+is(normalize_pkg_path('/', '.'), '.', 'Safe relative root dot');
+is(normalize_pkg_path('/', 'usr/..'), '.', 'Safe absurd relative root path');
+is(normalize_pkg_path('/usr/share/java', '../../../'), '.', 'Safe absurd relative path to root');
 
 # Unsafe
-ok(!resolve_pkg_path('/usr/share/ant', '../../../../etc/passwd'), 'Unsafe - relative escape root');
-ok(!resolve_pkg_path('/usr/share/ant', '/../etc/passwd'), 'Unsafe - absolute escape root');
+ok(!normalize_pkg_path('/usr/share/ant', '../../../../etc/passwd'), 'Unsafe - relative escape root');
+ok(!normalize_pkg_path('/usr/share/ant', '/../etc/passwd'), 'Unsafe - absolute escape root');

-- 
Debian package checker


Reply to: