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

lintian: r73 - in trunk: checks debian testset testset/filenames/debian



Author: jeroen
Date: 2004-02-27 01:34:42 +0100 (Fri, 27 Feb 2004)
New Revision: 73

Modified:
   trunk/checks/files
   trunk/checks/files.desc
   trunk/debian/changelog
   trunk/testset/filenames/debian/changelog
   trunk/testset/filenames/debian/rules
   trunk/testset/info_tags.filenames
   trunk/testset/tags.filenames
Log:
checks/filenames:
+ Revised the symlink detection stuff, it is now more rigorous, and has
  seperate warning for recursive symlinks that are otherwise not
  necessarily wrong (Closes: #118080)


Modified: trunk/checks/files
===================================================================
--- trunk/checks/files	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/checks/files	2004-02-27 00:34:42 UTC (rev 73)
@@ -483,71 +483,101 @@
     elsif ($perm =~ m/^l/) {
 	# link
 	# determine top-level directory of file
-	$file =~ m,^/?([^/]+),;
+	$file =~ m,^/?([^/]*),;
 	my $filetop = $1;
 	
-	if ($link =~ m,^/([^/]+),) {
-	    # absolute link
+	if ($link =~ m,//,) {
+	    print "E: $pkg $type: symlink-has-double-slash $file $link\n";
+	    # rest of the checks assume this isn't the case...
+	    goto NEXT_LINK;
+	} elsif ($link =~ m,./$,) {
+	    print "E: $pkg $type: symlink-ends-with-slash $file $link\n";
+	    # rest of the checks assume this isn't the case...
+	    goto NEXT_LINK;
+	}
 
+	if ($link =~ m,^/([^/]*),) {
+	    # absolute link, including link to /
+
 	    # determine top-level directory of link
-	    $link =~ m,^/?([^/]+),;
+	    $link =~ m,^/?([^/]*),;
 	    my $linktop = $1;
 
 	    if ($filetop eq $linktop) {
 		# absolute links within one toplevel directory are _not_ ok!
 		print "E: $pkg $type: symlink-should-be-relative $file $link\n";
 	    }
+
+	    # Any other case is already definitely non-recursive
+	    print "W: $pkg $type: symlink-is-self-recursive $file $link\n"
+	    	if $link eq '/';
+
 	} else {
-	    # relative link
+	    # relative link, we can assume from here that the link starts nor
+	    # ends with /
 
-	    my @pathcomponents = split('/', $file);
-	    # chop off filename
-	    splice(@pathcomponents,$#pathcomponents);
+	    my @filecomponents = split('/', $file);
+	    # chop off the name of the symlink
+	    pop @filecomponents;
 
+	    my @linkcomponents = split('/', $link);
+
 	    # handle `../' at beginning of $link
-	    my $my_link = $link;
-	    my $lastpop = "";
-	    while ($my_link =~ s,^../,,) {
-		if (@pathcomponents) {
-		    $lastpop = pop @pathcomponents;
+	    my $lastpop = undef;
+	    my $linkcomponent = undef;
+	    while ($linkcomponent = shift @linkcomponents) {
+		if ($linkcomponent eq '.') {
+		    print "E: $pkg $type: symlink-contains-spurious-segments $file $link\n"
+		    	unless $link eq '.';
+		    next;
+		}
+		last if $linkcomponent ne '..';
+		if (@filecomponents) {
+		    $lastpop = pop @filecomponents;
 		} else {
 		    print "E: $pkg $type: symlink-has-too-many-up-segments $file $link\n";
 		    goto NEXT_LINK;
 		}
 	    }
 
-	    $my_link =~ m,^/?([^/]+),;
-	    my $linktop = $1;
+	    if (!defined $linkcomponent) {
+		# After stripping all starting .. components, nothing left
+		print "W: $pkg $type: symlink-is-self-recursive $file $link\n";
+	    }
 
 	    # does the link go up and then down into the same directory?
-	    if ($linktop eq $lastpop) {
-		print "W: $pkg $type: lengthy-symlink $file $link\n";
+	    # (lastpop indicates there was a backref at all, no linkcomponent
+	    # means the symlink doesn't get up anymore)
+	    if (defined $lastpop && defined $linkcomponent &&
+		$linkcomponent eq $lastpop) {
+		print "E: $pkg $type: lengthy-symlink $file $link\n";
 	    }
 
-	    if ($#pathcomponents == -1) {
+	    if ($#filecomponents == -1) {
 		# we've reached the root directory
-		if ($filetop ne $linktop) {
-		    # relative link into other toplevel directory
+		if (!defined $linkcomponent || $filetop ne $linkcomponent) {
+		    # relative link into other toplevel directory.
+		    # this hits a relative symbolic link in the root too.
 		    print "E: $pkg $type: symlink-should-be-absolute $file $link\n";
 		}
 	    }
 
 	    # check additional segments for mistakes like `foo/../bar/'
-	    for my $linksegment (split('/', $my_link)) {
-		if ($linksegment eq '..') {
-		    print "E: $pkg $type: symlink-contains-up-and-down-segments $file $link\n";
-		    goto NEXT_LINK;
+	    foreach (@linkcomponents) {
+		if ($_ eq '..' || $_ eq '.') {
+		    print "E: $pkg $type: symlink-contains-spurious-segments $file $link\n";
+		    last;
 		}
 	    }
 	}
     NEXT_LINK:
 	
-	if ($link =~ m,\.(gz|z|Z|zip)\s*$,) {
+	if ($link =~ m,\.(gz|z|Z|bz|bz2|tgz|zip)\s*$,) {
 	    # symlink is pointing to a compressed file
 
 	    # symlink has correct extension?
 	    unless ($file =~ m,\.$1\s*$,) {
-		print "E: $pkg $type: gzipped-symlink-with-wrong-ext $file $link\n";
+		print "E: $pkg $type: compressed-symlink-with-wrong-ext $file $link\n";
 	    }
 	}
     }

Modified: trunk/checks/files.desc
===================================================================
--- trunk/checks/files.desc	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/checks/files.desc	2004-02-27 00:34:42 UTC (rev 73)
@@ -177,7 +177,7 @@
  <tt>/usr/doc/examples</tt> directory.  The new location for examples
  is <tt>/usr/share/doc/<i>pkg</i>/examples</tt>.
 
-Tag: gzipped-symlink-with-wrong-ext
+Tag: compressed-symlink-with-wrong-ext
 Type: error
 Info: The package installs a symbolic link pointing to a compressed file,
  but the symbolic link does not use the same file extension than the
@@ -185,9 +185,23 @@
  user or a program tries to access the file through the link.
 Ref: policy 10.5
 
+Tag: symlink-has-double-slash
+Type: error
+Info: This symlink contains two successive slashes (//). This is in violation
+ of policy, where it is stated that symlinks should be as short as possible
+Ref: policy 10.5
+
+Tag: symlink-ends-with-slash
+Type: error
+Info: This symlink ends with a slash (/). This is in violation
+ of policy, where it is stated that symlinks should be as short as possible
+Ref: policy 10.5
+
 Tag: symlink-should-be-relative
 Type: error
-Info: Usually, symbolic links should be relative.
+Info: Symlinks to files which are in the same top-level directory, should be
+ relative according to policy (i.e., files within /usr, should be relative
+ etc., while files from /usr to /etc should be absolute)
 Ref: policy 10.5
 
 Tag: symlink-should-be-absolute
@@ -217,15 +231,23 @@
 Info: The symlink references a directory beyond the root directory `/'.
 
 Tag: lengthy-symlink
-Type: warning
+Type: error
 Info: This link goes up, and then back down into the same subdirectory.
  Making it shorter will improve its chances of finding the right file
  if the user's system has lots of symlinked directories.
 Ref: policy 10.5
 
-Tag: symlink-contains-up-and-down-segments
+Tag: symlink-is-self-recursive
+Type: warning
+Info: The symbolic link is recursive to a higher directory of the symlink
+ itself. This means, that you can infinitely chdir with this symlink. This is
+ usually not okay, but sometimes wanted behaviour.
+
+Tag: symlink-contains-spurious-segments
 Type: error
-Info: The symbolic link goes up and down.
+Info: The symbolic link has needless segments like '..' and '.' in the middle.
+ These are unneeded, and make the link longer than it could be, which is in
+ violation of policy.
 Ref: policy 10.5
 
 Tag: bad-permissions-for-etc-cron.d-script

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/debian/changelog	2004-02-27 00:34:42 UTC (rev 73)
@@ -47,6 +47,10 @@
   * checks/debconf:
     + Update valid types, since currently 'title' is supported now too
       (Closes: #234379, #234608)
+  * checks/filenames:
+    + Revised the symlink detection stuff, it is now more rigorous, and has
+      seperate warning for recursive symlinks that are otherwise not
+      necessarily wrong (Closes: #118080)
 
  -- Frank Lichtenheld <djpig@debian.org>  Thu, 26 Feb 2004 21:52:14 +0100
 

Modified: trunk/testset/filenames/debian/changelog
===================================================================
--- trunk/testset/filenames/debian/changelog	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/testset/filenames/debian/changelog	2004-02-27 00:34:42 UTC (rev 73)
@@ -1,3 +1,9 @@
+filenames (7) unstable; urgency=low
+
+  * Add a dozen symlinks, some correct, some not
+
+ -- Jeroen van Wolffelaar <jeroen@wolffelaar.nl>  Fri, 27 Feb 2004 01:28:42 +0100
+
 filenames (6) unstable; urgency=low
 
   * Add perl files to check if

Modified: trunk/testset/filenames/debian/rules
===================================================================
--- trunk/testset/filenames/debian/rules	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/testset/filenames/debian/rules	2004-02-27 00:34:42 UTC (rev 73)
@@ -34,6 +34,7 @@
 	touch debian/tmp/usr/lib/menu/menu
 	chmod 644 debian/tmp/usr/lib/menu/*
 	install -d debian/tmp/usr/lib/perl5/foo
+	install -d debian/tmp/usr/lib/filenames
 	mkdir debian/tmp/usr/lib/perl5/.svn
 	mkdir debian/tmp/usr/lib/perl5/CVS
 	touch debian/tmp/usr/lib/perl5/foo/.packlist
@@ -49,6 +50,23 @@
 	gzip -9 debian/tmp/usr/share/doc/filenames/Changes
 	ln -s Changes.gz debian/tmp/usr/share/doc/filenames/changelog.gz
 	ln -s '../filenames/doc/version6.txt.gz' debian/tmp/usr/share/doc/filenames/version.txt.gz
+	ln -s ../../share/symlink debian/tmp/usr/lib/filenames/symlink1ok
+	ln -s ../../../etc/symlink debian/tmp/usr/lib/filenames/symlink1wrong
+	ln -s ../../../../etc/symlink debian/tmp/usr/lib/filenames/symlink2wrong
+	ln -s /etc/symlink debian/tmp/usr/lib/filenames/symlink2ok
+	ln -s /usr/lib/filenames/symlink2 debian/tmp/usr/lib/filenames/symlink3wrong
+	ln -s test debian/tmp/usr/lib/filenames/symlink3ok
+	ln -s ../filenames/symlink2 debian/tmp/usr/lib/filenames/symlink4wrong
+	ln -s ../menu/../somethingelse debian/tmp/usr/lib/filenames/symlink5wrong
+	ln -s ../menu/somethingelse debian/tmp/usr/lib/filenames/symlink4ok
+	ln -s ./file4 debian/tmp/usr/lib/filenames/symlink6wrong
+	ln -s ../menu/./something debian/tmp/usr/lib/filenames/symlink7wrong
+	ln -s ../menu//something debian/tmp/usr/lib/filenames/symlink8wrong
+	ln -s ../menu/something/ debian/tmp/usr/lib/filenames/symlink9wrong
+	ln -s .. debian/tmp/usr/lib/filenames/symlink5ok+warn
+	ln -s . debian/tmp/usr/lib/filenames/symlink6ok+warn
+	ln -s / debian/tmp/usr/lib/filenames/symlink7ok+warn
+	ln -s ../../.. debian/tmp/usr/lib/filenames/symlink10wrong
 	dpkg-gencontrol
 	dpkg --build debian/tmp ..
 

Modified: trunk/testset/info_tags.filenames
===================================================================
--- trunk/testset/info_tags.filenames	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/testset/info_tags.filenames	2004-02-27 00:34:42 UTC (rev 73)
@@ -91,14 +91,69 @@
 N:
 N:   Package contains a file which is empty.
 N:
-W: filenames: lengthy-symlink usr/share/doc/filenames/version.txt.gz ../filenames/doc/version6.txt.gz
+E: filenames: symlink-should-be-absolute usr/lib/filenames/symlink1wrong ../../../etc/symlink
 N:
+N:   Symbolic links between different top-level directories should be
+N:   absolute.
+N:   
+N:   Refer to Policy Manual, section 10.5 for details.
+N:
+E: filenames: symlink-has-too-many-up-segments usr/lib/filenames/symlink2wrong ../../../../etc/symlink
+N:
+N:   The symlink references a directory beyond the root directory `/'.
+N:
+E: filenames: symlink-should-be-relative usr/lib/filenames/symlink3wrong /usr/lib/filenames/symlink2
+N:
+N:   Symlinks to files which are in the same top-level directory, should be
+N:   relative according to policy (i.e., files within /usr, should be
+N:   relative etc., while files from /usr to /etc should be absolute)
+N:   
+N:   Refer to Policy Manual, section 10.5 for details.
+N:
+E: filenames: lengthy-symlink usr/lib/filenames/symlink4wrong ../filenames/symlink2
+N:
 N:   This link goes up, and then back down into the same subdirectory.
 N:   Making it shorter will improve its chances of finding the right file
 N:   if the user's system has lots of symlinked directories.
 N:   
 N:   Refer to Policy Manual, section 10.5 for details.
 N:
+E: filenames: symlink-contains-spurious-segments usr/lib/filenames/symlink5wrong ../menu/../somethingelse
+N:
+N:   The symbolic link has needless segments like '..' and '.' in the
+N:   middle. These are unneeded, and make the link longer than it could be,
+N:   which is in violation of policy.
+N:   
+N:   Refer to Policy Manual, section 10.5 for details.
+N:
+E: filenames: symlink-contains-spurious-segments usr/lib/filenames/symlink6wrong ./file4
+E: filenames: symlink-contains-spurious-segments usr/lib/filenames/symlink7wrong ../menu/./something
+E: filenames: symlink-has-double-slash usr/lib/filenames/symlink8wrong ../menu//something
+N:
+N:   This symlink contains two successive slashes (//). This is in
+N:   violation of policy, where it is stated that symlinks should be as
+N:   short as possible
+N:   
+N:   Refer to Policy Manual, section 10.5 for details.
+N:
+E: filenames: symlink-ends-with-slash usr/lib/filenames/symlink9wrong ../menu/something/
+N:
+N:   This symlink ends with a slash (/). This is in violation of policy,
+N:   where it is stated that symlinks should be as short as possible
+N:   
+N:   Refer to Policy Manual, section 10.5 for details.
+N:
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink5ok+warn ..
+N:
+N:   The symbolic link is recursive to a higher directory of the symlink
+N:   itself. This means, that you can infinitely chdir with this symlink.
+N:   This is usually not okay, but sometimes wanted behaviour.
+N:
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink6ok+warn .
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink7ok+warn /
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink10wrong ../../..
+E: filenames: symlink-should-be-absolute usr/lib/filenames/symlink10wrong ../../..
+E: filenames: lengthy-symlink usr/share/doc/filenames/version.txt.gz ../filenames/doc/version6.txt.gz
 W: filenames: package-installs-nonbinary-perl-in-usr-lib-perl5 usr/lib/perl5/foo/bar.pm
 N:
 N:   Architecture-independent Perl code should be placed in

Modified: trunk/testset/tags.filenames
===================================================================
--- trunk/testset/tags.filenames	2004-02-27 00:01:59 UTC (rev 72)
+++ trunk/testset/tags.filenames	2004-02-27 00:34:42 UTC (rev 73)
@@ -16,7 +16,21 @@
 W: filenames: package-contains-svn-control-dir usr/lib/perl5/.svn/
 W: filenames: package-contains-CVS-dir usr/lib/perl5/CVS/
 W: filenames: zero-byte-file-in-doc-directory usr/share/doc/filenames/examples/very_interesting_example
-W: filenames: lengthy-symlink usr/share/doc/filenames/version.txt.gz ../filenames/doc/version6.txt.gz
+E: filenames: symlink-should-be-absolute usr/lib/filenames/symlink1wrong ../../../etc/symlink
+E: filenames: symlink-has-too-many-up-segments usr/lib/filenames/symlink2wrong ../../../../etc/symlink
+E: filenames: symlink-should-be-relative usr/lib/filenames/symlink3wrong /usr/lib/filenames/symlink2
+E: filenames: lengthy-symlink usr/lib/filenames/symlink4wrong ../filenames/symlink2
+E: filenames: symlink-contains-spurious-segments usr/lib/filenames/symlink5wrong ../menu/../somethingelse
+E: filenames: symlink-contains-spurious-segments usr/lib/filenames/symlink6wrong ./file4
+E: filenames: symlink-contains-spurious-segments usr/lib/filenames/symlink7wrong ../menu/./something
+E: filenames: symlink-has-double-slash usr/lib/filenames/symlink8wrong ../menu//something
+E: filenames: symlink-ends-with-slash usr/lib/filenames/symlink9wrong ../menu/something/
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink5ok+warn ..
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink6ok+warn .
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink7ok+warn /
+W: filenames: symlink-is-self-recursive usr/lib/filenames/symlink10wrong ../../..
+E: filenames: symlink-should-be-absolute usr/lib/filenames/symlink10wrong ../../..
+E: filenames: lengthy-symlink usr/share/doc/filenames/version.txt.gz ../filenames/doc/version6.txt.gz
 W: filenames: package-installs-nonbinary-perl-in-usr-lib-perl5 usr/lib/perl5/foo/bar.pm
 E: filenames: bad-menu-file-name usr/lib/menu/menu
 E: filenames: postinst-does-not-call-updatemenus usr/lib/menu/menu



Reply to: