diff options
author | rillig <rillig@pkgsrc.org> | 2006-02-26 17:40:44 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-02-26 17:40:44 +0000 |
commit | 30f102136d1bc88a19e43bcb1465c8ee1394c66a (patch) | |
tree | e9e12474a7dfb6c676c1d64080e06f6c228d40c1 /pkgtools/pkglint | |
parent | b411534837b21b9baf49c96accda01cbd25ca6bd (diff) | |
download | pkgsrc-30f102136d1bc88a19e43bcb1465c8ee1394c66a.tar.gz |
- Improved checking of sed commands that are used in the SUBST
framework. Now, unescaped shell special characters are detected.
Diffstat (limited to 'pkgtools/pkglint')
-rw-r--r-- | pkgtools/pkglint/files/makevars.map | 5 | ||||
-rw-r--r-- | pkgtools/pkglint/files/pkglint.pl | 57 |
2 files changed, 56 insertions, 6 deletions
diff --git a/pkgtools/pkglint/files/makevars.map b/pkgtools/pkglint/files/makevars.map index d93f333ea65..b7737b5e843 100644 --- a/pkgtools/pkglint/files/makevars.map +++ b/pkgtools/pkglint/files/makevars.map @@ -1,4 +1,4 @@ -# $NetBSD: makevars.map,v 1.66 2006/02/26 04:26:52 rillig Exp $ +# $NetBSD: makevars.map,v 1.67 2006/02/26 17:40:44 rillig Exp $ # # This file contains the guessed type of some variables, according to @@ -326,8 +326,7 @@ SUBST_FILES List of Pathmask SUBST_FILTER_CMD List of ShellWord # ^^ more appropriately, a Shellcommand SUBST_MESSAGE Message -SUBST_SED List of ShellWord -# ^^ This may be changed to a List+ later. +SUBST_SED SedCommands SUBST_STAGE Stage SVR4_PKGNAME SVR4PkgName TEST_DIRS List of WrksrcSubdirectory diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl index 4a47dd617ff..9c8a126c96d 100644 --- a/pkgtools/pkglint/files/pkglint.pl +++ b/pkgtools/pkglint/files/pkglint.pl @@ -1,5 +1,5 @@ #! @PERL@ -# $NetBSD: pkglint.pl,v 1.534 2006/02/26 16:21:14 rillig Exp $ +# $NetBSD: pkglint.pl,v 1.535 2006/02/26 17:40:44 rillig Exp $ # # pkglint - static analyzer and checker for pkgsrc packages @@ -1999,6 +1999,17 @@ sub tablen($) { return $len; } +sub shell_split($) { + my ($text) = @_; + my ($words); + + $words = []; + while ($text =~ s/$regex_shellword//) { + push(@{$words}, $1); + } + return (($text =~ qr"^\s*$") ? $words : false); +} + # # Loading package-specific data from files. # @@ -2428,7 +2439,7 @@ sub checkline_mk_shellword($$$) { if ($state == SWST_PLAIN && defined($mod) && $mod =~ qr":Q$") { # Fine. - } elsif (($state == SWST_SQUOT || $state == SWST_DQUOT) && $varname =~ qr"^(?:.*DIR|.*FILE|.*PATH|.*_VAR|PREFIX|LOCALBASE|PKGNAME)$") { + } elsif (($state == SWST_SQUOT || $state == SWST_DQUOT) && $varname =~ qr"^(?:.*DIR|.*FILE|.*PATH|.*_VAR|PREFIX|.*BASE|PKGNAME)$") { # This is ok if we don't allow these # variables to have embedded [\$\\\"\'\`]. @@ -3090,6 +3101,46 @@ sub checkline_mk_vartype_basic($$$$$$$) { $line->log_error("SVR4_PKGNAME must not be longer than 5 characters."); } + } elsif ($type eq "SedCommands") { + my $words = shell_split($value); + if (!$words) { + $line->log_error("Invalid shell words in sed commands."); + + } else { + my $nwords = scalar(@{$words}); + my $ncommands = 0; + + for (my $i = 0; $i < $nwords; $i++) { + my $word = $words->[$i]; + checkline_mk_shellword($line, $word, true); + + if ($word eq "-e") { + if ($i + 1 < $nwords) { + # Check the real sed command here. + $i++; + $ncommands++; + if ($ncommands > 1) { + $line->log_warning("Each sed command should appear in an assignment of its own."); + } + checkline_mk_shellword($line, $word, true); + } else { + $line->log_error("The -e option to sed requires an argument."); + } + } elsif ($word eq "-E") { + # Switch to extended regular expressions mode. + + } elsif ($word eq "-n") { + # Don't print lines per default. + + } elsif ($i == 0 && $word =~ qr"^([\"']?)\d*s(.).*\2\1g?$") { + $line->log_warning("Please always use \"-e\" in sed commands, even if there is only one substitution."); + + } else { + $line->log_warning("Unknown sed command ${word}."); + } + } + } + } elsif ($type eq "ShellCommand") { checkline_mk_shellcmd($line, $value); @@ -3314,7 +3365,7 @@ sub checkline_mk_vartype($$$$$) { } } else { - checkline_mk_vartype_basic($line, $varname, $type, $op, $value, $comment, false); + checkline_mk_vartype_basic($line, $varname, $type, $op, $value, $comment, ($type eq "SedCommands")); } } |