Skip to content

Commit c0a5c89

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: improve octal permissions tests
Add world writable permissions tests for the various functions like debugfs etc... Add $String type for $FuncArg so that string constants are matched. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 62ec818 commit c0a5c89

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/checkpatch.pl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ sub hash_show_words {
298298
our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
299299
our $Int = qr{[0-9]+$Int_type?};
300300
our $Octal = qr{0[0-7]+$Int_type?};
301+
our $String = qr{"[X\t]*"};
301302
our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
302303
our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
303304
our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
@@ -517,7 +518,7 @@ sub build_types {
517518

518519
our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
519520
our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
520-
our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
521+
our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
521522

522523
our $declaration_macros = qr{(?x:
523524
(?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,2}\s*\(|
@@ -5261,6 +5262,9 @@ sub process {
52615262
length($val) ne 4)) {
52625263
ERROR("NON_OCTAL_PERMISSIONS",
52635264
"Use 4 digit octal (0777) not decimal permissions\n" . $herecurr);
5265+
} elsif ($val =~ /^$Octal$/ && (oct($val) & 02)) {
5266+
ERROR("EXPORTED_WORLD_WRITABLE",
5267+
"Exporting writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
52645268
}
52655269
}
52665270
}

0 commit comments

Comments
 (0)