mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] checkpatch: add --max-file-size option
@ 2020-06-10 20:56 Scott Branden
  2020-06-10 21:08 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Scott Branden @ 2020-06-10 20:56 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches
  Cc: BCM Kernel Feedback, linux-kernel, Scott Branden

Add --max-file-size option (default off) to limit size of files
that checkpatch processes.  Such an option is useful when checkpatch
is run automatically during checkins to a source control system and
someone acccidently or purposely attempt to commit massive size files
to the system.  If the checkpatch script runs on such files it could take
a long time to run and limit the server's ability to perform other
operations.

Signed-off-by: Scott Branden <scott.branden@broadcom.com>
---
 scripts/checkpatch.pl | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9fa90457b270..5f0304a9f013 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -53,6 +53,7 @@ my %ignore_type = ();
 my @ignore = ();
 my $help = 0;
 my $configuration_file = ".checkpatch.conf";
+my $max_file_size = -1;
 my $max_line_length = 100;
 my $ignore_perl_version = 0;
 my $minimum_perl_version = 5.10.0;
@@ -99,6 +100,7 @@ Options:
   --types TYPE(,TYPE2...)    show only these comma separated message types
   --ignore TYPE(,TYPE2...)   ignore various comma separated message types
   --show-types               show the specific message type in the output
+  --max-file-size=n          set the maximum file size, if exceeded, exit
   --max-line-length=n        set the maximum line length, (default $max_line_length)
                              if exceeded, warn on patches
                              requires --strict for use with --file
@@ -219,6 +221,7 @@ GetOptions(
 	'types=s'	=> \@use,
 	'show-types!'	=> \$show_types,
 	'list-types!'	=> \$list_types,
+	'max-file-size=i' => \$max_file_size,
 	'max-line-length=i' => \$max_line_length,
 	'min-conf-desc-length=i' => \$min_conf_desc_length,
 	'tab-size=i'	=> \$tabsize,
@@ -1061,6 +1064,15 @@ for my $filename (@ARGV) {
 	} else {
 		$vname = $filename;
 	}
+
+	if ($max_file_size > 0) {
+		my $filesize = -s$FILE;
+
+		if ($filesize > $max_file_size) {
+			die "$P: $filename: filesize:$filesize > $max_file_size\n";
+		}
+	}
+
 	while (<$FILE>) {
 		chomp;
 		push(@rawlines, $_);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] checkpatch: add --max-file-size option
  2020-06-10 20:56 [PATCH] checkpatch: add --max-file-size option Scott Branden
@ 2020-06-10 21:08 ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2020-06-10 21:08 UTC (permalink / raw)
  To: Scott Branden, Andy Whitcroft; +Cc: BCM Kernel Feedback, linux-kernel

On Wed, 2020-06-10 at 13:56 -0700, Scott Branden wrote:
> Add --max-file-size option (default off) to limit size of files
> that checkpatch processes.  Such an option is useful when checkpatch
> is run automatically during checkins to a source control system and
> someone acccidently or purposely attempt to commit massive size files
> to the system.  If the checkpatch script runs on such files it could take
> a long time to run and limit the server's ability to perform other
> operations.

Does everything need to be in checkpatch or can this facility
be run by a separate script that does the file size validation
before running checkpatch?

Also:

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> +	if ($max_file_size > 0) {
> +		my $filesize = -s$FILE;

Does this work if the input file is from STDIN?
I'd guess it does not.

I think this might be better using (stat($FILE))[7]
or at least a space between -s and $file.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-10 21:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10 20:56 [PATCH] checkpatch: add --max-file-size option Scott Branden
2020-06-10 21:08 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®