Package: lintian
Version: 1.23.21
Severity: wishlist
Tags: patch

*** Please type your report below this line ***

The lintian check-scripts:

/usr/share/lintian/checks/{control-files,files,menus,shared-libs}

...each define a "perm2oct" function to allow them to convert a
ls-style string like drwxr-xr-x into a numeric value like 0755.
However, the logic used in each case is incapable of coping with
pathological strings like drwSr-Sr-T (=07644), and would read that
as equivalent to the inoffensive drwxr-xr-x. 

Now, you could fix this by simple-mindedly extending the existing
logic, or you could use something a bit fancier.  Below are buggy,
plain-fixed and fancy-fixed versions of the function; attached is a
patch using the plain version.

######################################################################
        BUGGY
######################################################################
# translate permission strings like `-rwxrwxrwx' into an octal number
sub perm2oct {
    my ($t) = @_;

    my $o = 0;

    $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;

    $o += 04000 if $3 eq 's';   # set-uid
    $o += 02000 if $6 eq 's';   # set-gid
    $o += 01000 if $9 eq 't';   # sticky bit
    $o += 00400 if $1 ne '-';   # owner read
    $o += 00200 if $2 ne '-';   # owner write
    $o += 00100 if $3 ne '-';   # owner execute
    $o += 00040 if $4 ne '-';   # owner read
    $o += 00020 if $5 ne '-';   # owner write
    $o += 00010 if $6 ne '-';   # owner execute
    $o += 00004 if $7 ne '-';   # owner read
    $o += 00002 if $8 ne '-';   # owner write
    $o += 00001 if $9 ne '-';   # owner execute

    return $o;
}
######################################################################
        PLAIN-FIXED
######################################################################
# translate permission strings like `-rwxrwxrwx' into an octal number
sub perm2oct {
    my ($t) = @_;

    my $o = 0;

    $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;

    $o += 00400 if $1 eq 'r';   # owner read
    $o += 00200 if $2 eq 'w';   # owner write
    $o += 00100 if $3 eq 'x';   # owner execute
    $o += 04000 if $3 eq 'S';   # setuid
    $o += 04100 if $3 eq 's';   # setuid + owner execute
    $o += 00040 if $4 eq 'r';   # group read
    $o += 00020 if $5 eq 'w';   # group write
    $o += 00010 if $6 eq 'x';   # group execute
    $o += 02000 if $6 eq 'S';   # setgid
    $o += 02010 if $6 eq 's';   # setgid + group execute
    $o += 00004 if $7 eq 'r';   # other read
    $o += 00002 if $8 eq 'w';   # other write
    $o += 00001 if $9 eq 'x';   # other execute
    $o += 01000 if $9 eq 'T';   # stickybit
    $o += 01001 if $9 eq 't';   # stickybit + other execute

    return $o;
}
######################################################################
        FANCY-FIXED
######################################################################
# translate permission strings like `-rwxrwxrwx' into an octal number
sub perm2oct {
    my ($t) = @_;
    my $o = 0;
    $t =~ /^.(...)(...)(...)/o;
    my @ugo = ($1, $2, $3);
    my @rwx = ('[xst]', 'w', 'r');
    for my $i (0..8) {
        unless  ($i%3) {
             $_ = pop @ugo;
             /[stST]/ and $o += 1<<(9+$i/3);
        }
        /$rwx[$i%3]/ and $o += 1<<$i;
    }
    return $o; # though this isn't oct-shaped!
}
######################################################################

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing'), (50, 'unstable')
Architecture: i386 (i586)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17.hurakan
Locale: LANG=en_GB, LC_CTYPE=en_GB (charmap=ISO-8859-1)

Versions of packages lintian depends on:
ii  binutils             2.16.1cvs20060413-1 The GNU assembler, linker and bina
ii  diffstat             1.41-1              produces graph of changes introduc
ii  dpkg-dev             1.13.21             package building tools for Debian
ii  file                 4.17-2              Determines file type using "magic"
ii  gettext              0.14.5-4            GNU Internationalization utilities
ii  intltool-debian      0.34.2+20060512     Help i18n of RFC822 compliant conf
ii  libparse-debianchang 1.0-1               parse Debian changelogs and output
ii  man-db               2.4.3-3             The on-line manual pager
ii  perl [libdigest-md5- 5.8.8-4             Larry Wall's Practical Extraction 

lintian recommends no packages.

-- no debconf information
-- 
JBR
Ankh kak! (Ancient Egyptian blessing)
diff -ru lintian-1.23.22.pristine/checks/control-files 
lintian-1.23.22/checks/control-files
--- lintian-1.23.22.pristine/checks/control-files       2006-01-02 
09:19:16.000000000 +0000
+++ lintian-1.23.22/checks/control-files        2006-06-29 20:34:16.000000000 
+0100
@@ -112,18 +112,21 @@
 
     $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;
 
-    $o += 04000 if $3 eq 's';  # set-uid
-    $o += 02000 if $6 eq 's';  # set-gid
-    $o += 01000 if $9 eq 't';  # sticky bit
-    $o += 00400 if $1 ne '-';  # owner read
-    $o += 00200 if $2 ne '-';  # owner write
-    $o += 00100 if $3 ne '-';  # owner execute
-    $o += 00040 if $4 ne '-';  # owner read
-    $o += 00020 if $5 ne '-';  # owner write
-    $o += 00010 if $6 ne '-';  # owner execute
-    $o += 00004 if $7 ne '-';  # owner read
-    $o += 00002 if $8 ne '-';  # owner write
-    $o += 00001 if $9 ne '-';  # owner execute
+    $o += 00400 if $1 eq 'r';  # owner read
+    $o += 00200 if $2 eq 'w';  # owner write
+    $o += 00100 if $3 eq 'x';  # owner execute
+    $o += 04000 if $3 eq 'S';  # setuid
+    $o += 04100 if $3 eq 's';  # setuid + owner execute
+    $o += 00040 if $4 eq 'r';  # group read
+    $o += 00020 if $5 eq 'w';  # group write
+    $o += 00010 if $6 eq 'x';  # group execute
+    $o += 02000 if $6 eq 'S';  # setgid
+    $o += 02010 if $6 eq 's';  # setgid + group execute
+    $o += 00004 if $7 eq 'r';  # other read
+    $o += 00002 if $8 eq 'w';  # other write
+    $o += 00001 if $9 eq 'x';  # other execute
+    $o += 01000 if $9 eq 'T';  # stickybit
+    $o += 01001 if $9 eq 't';  # stickybit + other execute
 
     return $o;
 }
diff -ru lintian-1.23.22.pristine/checks/files lintian-1.23.22/checks/files
--- lintian-1.23.22.pristine/checks/files       2006-05-04 04:37:21.000000000 
+0100
+++ lintian-1.23.22/checks/files        2006-06-29 20:42:21.000000000 +0100
@@ -769,20 +769,23 @@
 
     my $o = 0;
 
-    $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/;
+    $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;
 
-    $o += 04000 if $3 eq 's';  # set-uid
-    $o += 02000 if $6 eq 's';  # set-gid
-    $o += 01000 if $9 eq 't';  # sticky bit
-    $o += 00400 if $1 ne '-';  # owner read
-    $o += 00200 if $2 ne '-';  # owner write
-    $o += 00100 if $3 ne '-';  # owner execute
-    $o += 00040 if $4 ne '-';  # owner read
-    $o += 00020 if $5 ne '-';  # owner write
-    $o += 00010 if $6 ne '-';  # owner execute
-    $o += 00004 if $7 ne '-';  # owner read
-    $o += 00002 if $8 ne '-';  # owner write
-    $o += 00001 if $9 ne '-';  # owner execute
+    $o += 00400 if $1 eq 'r';  # owner read
+    $o += 00200 if $2 eq 'w';  # owner write
+    $o += 00100 if $3 eq 'x';  # owner execute
+    $o += 04000 if $3 eq 'S';  # setuid
+    $o += 04100 if $3 eq 's';  # setuid + owner execute
+    $o += 00040 if $4 eq 'r';  # group read
+    $o += 00020 if $5 eq 'w';  # group write
+    $o += 00010 if $6 eq 'x';  # group execute
+    $o += 02000 if $6 eq 'S';  # setgid
+    $o += 02010 if $6 eq 's';  # setgid + group execute
+    $o += 00004 if $7 eq 'r';  # other read
+    $o += 00002 if $8 eq 'w';  # other write
+    $o += 00001 if $9 eq 'x';  # other execute
+    $o += 01000 if $9 eq 'T';  # stickybit
+    $o += 01001 if $9 eq 't';  # stickybit + other execute
 
     return $o;
 }
diff -ru lintian-1.23.22.pristine/checks/menus lintian-1.23.22/checks/menus
--- lintian-1.23.22.pristine/checks/menus       2006-05-09 02:53:09.000000000 
+0100
+++ lintian-1.23.22/checks/menus        2006-06-29 20:35:08.000000000 +0100
@@ -260,20 +260,23 @@
 
     my $o = 0;
 
-    $t =~ /^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;
+    $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;
 
-    $o += 04000 if $3 eq 's';  # set-uid
-    $o += 02000 if $6 eq 's';  # set-gid
-    $o += 01000 if $9 eq 't';  # sticky bit
-    $o += 00400 if $1 ne '-';  # owner read
-    $o += 00200 if $2 ne '-';  # owner write
-    $o += 00100 if $3 ne '-';  # owner execute
-    $o += 00040 if $4 ne '-';  # owner read
-    $o += 00020 if $5 ne '-';  # owner write
-    $o += 00010 if $6 ne '-';  # owner execute
-    $o += 00004 if $7 ne '-';  # owner read
-    $o += 00002 if $8 ne '-';  # owner write
-    $o += 00001 if $9 ne '-';  # owner execute
+    $o += 00400 if $1 eq 'r';  # owner read
+    $o += 00200 if $2 eq 'w';  # owner write
+    $o += 00100 if $3 eq 'x';  # owner execute
+    $o += 04000 if $3 eq 'S';  # setuid
+    $o += 04100 if $3 eq 's';  # setuid + owner execute
+    $o += 00040 if $4 eq 'r';  # group read
+    $o += 00020 if $5 eq 'w';  # group write
+    $o += 00010 if $6 eq 'x';  # group execute
+    $o += 02000 if $6 eq 'S';  # setgid
+    $o += 02010 if $6 eq 's';  # setgid + group execute
+    $o += 00004 if $7 eq 'r';  # other read
+    $o += 00002 if $8 eq 'w';  # other write
+    $o += 00001 if $9 eq 'x';  # other execute
+    $o += 01000 if $9 eq 'T';  # stickybit
+    $o += 01001 if $9 eq 't';  # stickybit + other execute
 
     return $o;
 }
diff -ru lintian-1.23.22.pristine/checks/shared-libs 
lintian-1.23.22/checks/shared-libs
--- lintian-1.23.22.pristine/checks/shared-libs 2006-04-04 21:20:47.000000000 
+0100
+++ lintian-1.23.22/checks/shared-libs  2006-06-29 20:35:35.000000000 +0100
@@ -403,18 +403,21 @@
 
     $t =~ m/^.(.)(.)(.)(.)(.)(.)(.)(.)(.)/o;
 
-    $o += 04000 if $3 eq 's';  # set-uid
-    $o += 02000 if $6 eq 's';  # set-gid
-    $o += 01000 if $9 eq 't';  # sticky bit
-    $o += 00400 if $1 ne '-';  # owner read
-    $o += 00200 if $2 ne '-';  # owner write
-    $o += 00100 if $3 ne '-';  # owner execute
-    $o += 00040 if $4 ne '-';  # owner read
-    $o += 00020 if $5 ne '-';  # owner write
-    $o += 00010 if $6 ne '-';  # owner execute
-    $o += 00004 if $7 ne '-';  # owner read
-    $o += 00002 if $8 ne '-';  # owner write
-    $o += 00001 if $9 ne '-';  # owner execute
+    $o += 00400 if $1 eq 'r';  # owner read
+    $o += 00200 if $2 eq 'w';  # owner write
+    $o += 00100 if $3 eq 'x';  # owner execute
+    $o += 04000 if $3 eq 'S';  # setuid
+    $o += 04100 if $3 eq 's';  # setuid + owner execute
+    $o += 00040 if $4 eq 'r';  # group read
+    $o += 00020 if $5 eq 'w';  # group write
+    $o += 00010 if $6 eq 'x';  # group execute
+    $o += 02000 if $6 eq 'S';  # setgid
+    $o += 02010 if $6 eq 's';  # setgid + group execute
+    $o += 00004 if $7 eq 'r';  # other read
+    $o += 00002 if $8 eq 'w';  # other write
+    $o += 00001 if $9 eq 'x';  # other execute
+    $o += 01000 if $9 eq 'T';  # stickybit
+    $o += 01001 if $9 eq 't';  # stickybit + other execute
 
     return $o;
 }

Reply via email to