Commit b401f56f authored by Tobin C. Harding's avatar Tobin C. Harding

leaking_addresses: simplify path skipping

Currently script has multiple configuration arrays.  This is confusing,
evident by the fact that a bunch of the entries are in the wrong place.
We can simplify the code by just having a single array for absolute
paths to skip and a single array for file names to skip wherever they
appear in the scanned directory tree.  There are also currently multiple
subroutines to handle the different arrays, we can reduce these to a
single subroutine also.

Simplify the path skipping code.
Signed-off-by: default avatarTobin C. Harding <me@tobin.cc>
parent e2858cad
...@@ -48,20 +48,16 @@ my $kernel_config_file = ""; # Kernel configuration file. ...@@ -48,20 +48,16 @@ my $kernel_config_file = ""; # Kernel configuration file.
my $opt_32bit = 0; # Scan 32-bit kernel. my $opt_32bit = 0; # Scan 32-bit kernel.
my $page_offset_32bit = 0; # Page offset for 32-bit kernel. my $page_offset_32bit = 0; # Page offset for 32-bit kernel.
# Do not parse these files (absolute path). # Skip these absolute paths.
my @skip_parse_files_abs = ('/proc/kmsg', my @skip_abs = (
'/proc/kcore', '/proc/kmsg',
'/proc/fs/ext4/sdb1/mb_groups',
'/proc/1/fd/3',
'/sys/firmware/devicetree',
'/proc/device-tree', '/proc/device-tree',
'/sys/firmware/devicetree',
'/sys/kernel/debug/tracing/trace_pipe', '/sys/kernel/debug/tracing/trace_pipe',
'/sys/kernel/security/apparmor/revision'); '/sys/kernel/security/apparmor/revision');
# Do not parse these files under any subdirectory. # Skip these under any subdirectory.
my @skip_parse_files_any = ('0', my @skip_any = (
'1',
'2',
'pagemap', 'pagemap',
'events', 'events',
'access', 'access',
...@@ -69,20 +65,9 @@ my @skip_parse_files_any = ('0', ...@@ -69,20 +65,9 @@ my @skip_parse_files_any = ('0',
'snapshot_raw', 'snapshot_raw',
'trace_pipe_raw', 'trace_pipe_raw',
'ptmx', 'ptmx',
'trace_pipe'); 'trace_pipe',
# Do not walk these directories (absolute path).
my @skip_walk_dirs_abs = ();
# Do not walk these directories under any subdirectory.
my @skip_walk_dirs_any = ('self',
'thread-self',
'cwd',
'fd', 'fd',
'usbmon', 'usbmon');
'stderr',
'stdin',
'stdout');
sub help sub help
{ {
...@@ -417,26 +402,20 @@ sub parse_dmesg ...@@ -417,26 +402,20 @@ sub parse_dmesg
# True if we should skip this path. # True if we should skip this path.
sub skip sub skip
{ {
my ($path, $paths_abs, $paths_any) = @_; my ($path) = @_;
foreach (@$paths_abs) { foreach (@skip_abs) {
return 1 if (/^$path$/); return 1 if (/^$path$/);
} }
my($filename, $dirs, $suffix) = fileparse($path); my($filename, $dirs, $suffix) = fileparse($path);
foreach (@$paths_any) { foreach (@skip_any) {
return 1 if (/^$filename$/); return 1 if (/^$filename$/);
} }
return 0; return 0;
} }
sub skip_parse
{
my ($path) = @_;
return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any);
}
sub timed_parse_file sub timed_parse_file
{ {
my ($file) = @_; my ($file) = @_;
...@@ -466,12 +445,6 @@ sub parse_file ...@@ -466,12 +445,6 @@ sub parse_file
return; return;
} }
if (skip_parse($file)) {
dprint "skipping file: $file\n";
return;
}
dprint "parsing: $file\n";
open my $fh, "<", $file or return; open my $fh, "<", $file or return;
while ( <$fh> ) { while ( <$fh> ) {
if (may_leak_address($_)) { if (may_leak_address($_)) {
...@@ -481,21 +454,12 @@ sub parse_file ...@@ -481,21 +454,12 @@ sub parse_file
close $fh; close $fh;
} }
# True if we should skip walking this directory.
sub skip_walk
{
my ($path) = @_;
return skip($path, \@skip_walk_dirs_abs, \@skip_walk_dirs_any)
}
# Recursively walk directory tree. # Recursively walk directory tree.
sub walk sub walk
{ {
my @dirs = @_; my @dirs = @_;
while (my $pwd = shift @dirs) { while (my $pwd = shift @dirs) {
next if (skip_walk($pwd));
next if (!opendir(DIR, $pwd)); next if (!opendir(DIR, $pwd));
my @files = readdir(DIR); my @files = readdir(DIR);
closedir(DIR); closedir(DIR);
...@@ -506,11 +470,15 @@ sub walk ...@@ -506,11 +470,15 @@ sub walk
my $path = "$pwd/$file"; my $path = "$pwd/$file";
next if (-l $path); next if (-l $path);
next if (skip($path));
if (-d $path) { if (-d $path) {
push @dirs, $path; push @dirs, $path;
} else { next;
timed_parse_file($path);
} }
dprint "parsing: $path\n";
timed_parse_file($path);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment