Skip to contentSkip to conversation

scripts/checkpatch.pl: Warn on non-executable files created with non 100644 file permissions

PATCH In review Joe Perches 4 participants 4 messages Oct 6, 2010 – Oct 11, 2010 Checkpatch

lore
Share & tools
lore

Joe Perches

author maintainer
#0 lore raw

PATCH 1/1 scripts/checkpatch.pl: Warn on non-executable files created with non 100644 file permissions

---
 scripts/checkpatch.pl |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +8 -0
index 2039acd..6f8a1d4 100755
@@ -1346,6 +1346,14 @@ sub process {
 			}
 		}
 
+		if ($rawline =~ /^ create mode (\d+) ([\w\.\/\-]+)$/) {
+			my $mode = $1;
+			my $file = $2;
+			if ($mode ne "100644" && !($file =~ /\.(sh|pl|py|awk)$/)) {
+				WARN("FILE '$file' should probably use file permission 100644 not $mode\n" . $herecurr);
+			}
+		}
+
 # Check for wrappage within a valid hunk of the file
 		if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
 			ERROR("patch seems to be corrupt (line wrapped?)\n" .
#1 lore raw
Quoted 10 lines · Joe Perches
---
 scripts/checkpatch.pl |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +0 -0
index 2039acd..6f8a1d4 100755

scripts/checkpatch.pl sub process { · line 1349

Quoted 4 lines
scripts/checkpatch.pl +1 -0
@@ -1346,6 +1346,14 @@ sub process {
 			}
 		}
 
+		if ($rawline =~ /^ create mode (\d+) ([\w\.\/\-]+)$/) {

Do you really need to escape ./- in the character-class? ISTR this is not needed.

scripts/checkpatch.pl sub process { · line 1354

Quoted 5 lines
scripts/checkpatch.pl +5 -0
+			my $mode = $1;
+			my $file = $2;
+			if ($mode ne "100644" && !($file =~ /\.(sh|pl|py|awk)$/)) {
+				WARN("FILE '$file' should probably use file permission 100644 not $mode\n" . $herecurr);
+			}

What about checking for no filename extension, too, and changing the message to something like "use proper file permission or proper extension"?

Quoted 12 lines
scripts/checkpatch.pl +2 -1
+		}
+
 # Check for wrappage within a valid hunk of the file
 		if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
 			ERROR("patch seems to be corrupt (line wrapped?)\n" .
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#2 lore raw
Quoted 9 lines · Wolfram Sang

scripts/checkpatch.pl sub process { · line 1354

Quoted 5 lines · Joe Perches
scripts/checkpatch.pl +5 -0
+			my $mode = $1;
+			my $file = $2;
+			if ($mode ne "100644" && !($file =~ /\.(sh|pl|py|awk)$/)) {
+				WARN("FILE '$file' should probably use file permission 100644 not $mode\n" . $herecurr);
+			}

What about checking for no filename extension, too, and changing the message to something like "use proper file permission or proper extension"?

That would result in too many false positives, I'm afraid. What about checking for files with a shebang?

Michal

#3 lore raw
In reply to Joe Perches
Quoted 8 lines · Joe Perches

+               if ($rawline =~ /^ create mode (\d+) ([\w\.\/\-]+)$/) {
+                       my $mode = $1;
+                       my $file = $2;
+                       if ($mode ne "100644" && !($file =~ /\.(sh|pl|py|awk)$/)) {
+                               WARN("FILE '$file' should probably use file permission 100644 not $mode\n" . $herecurr);
+                       }
+               }
+

There's a vaguely similar patch already in -mm. That one also handles mode changes and doesn't require the presence of the diff summary. Have a look in case you missed it, maybe it does most of what you want and you can base something on that:

http://userweb.kernel.org/~akpm/mmotm/broken-out/checkpatch-check-for-incorrect-permissions.patch