Skip to contentSkip to conversation

Minor bug fixes to leaking_addresses.pl

PATCH In review Tobin C. Harding 4 participants 10 messages Feb 7, 2019 – Feb 14, 2019 LEAKING_ADDRESSES

lore
Share & tools
lore
#0 lore raw

cover Minor bug fixes to leaking_addresses.pl

Hi,

Here are a few minor fixes/improvements to scripts/leaking_addresses.pl

Patch 1: Fixes places where I don't know how to Perl.

Patch 2: Removes --version command line option, completely this time.

Patch 3: Fix a bug in the command line options parsing.

thanks,
Tobin.

Tobin C. Harding (3):
leaking_addresses: Fix calls to dprint
leaking_addresses: Completely remove --version flag
leaking_addresses: Expand tilde in output file name

 scripts/leaking_addresses.pl | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 leaking_addresses: Fix calls to dprint

Currently calls to function dprint() are non uniform and at times incorrect.

Use uniform _correct_ call to function dprint().

---
 scripts/leaking_addresses.pl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/leaking_addresses.pl +3 -3
index 6a897788f5a7..214c12be8c86 100755
@@ -231,7 +231,7 @@ sub get_kernel_config_option
 		my $tmp_file = "/tmp/tmpkconf";
 
 		if (system("gunzip < /proc/config.gz > $tmp_file")) {
-			dprint "$0: system(gunzip < /proc/config.gz) failed\n";
+			dprint("system(gunzip < /proc/config.gz) failed\n");
 			return "";
 		} else {
 			@config_files = ($tmp_file);
@@ -243,7 +243,7 @@ sub get_kernel_config_option
 	}
 
 	foreach my $file (@config_files) {
-		dprint("parsing config file: %s\n", $file);
+		dprint("parsing config file: $file\n");
 		$value = option_from_file($option, $file);
 		if ($value ne "") {
 			last;
@@ -502,7 +502,7 @@ sub walk
 				next;
 			}
 
-			dprint "parsing: $path\n";
+			dprint("parsing: $path\n");
 			timed_parse_file($path);
 		}
 	}
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/3 leaking_addresses: Completely remove --version flag

In reply to Tobin C. Harding

Recently attempt to remove the '--version' flag was made, badly. I failed to remove mention of it from the help output. And also I failed to actually remove the flag from the options list.

_Completely_ remove --version flag.

---
 scripts/leaking_addresses.pl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/leaking_addresses.pl +1 -2
index 214c12be8c86..ef9e5b2a1614 100755
@@ -97,7 +97,7 @@ Options:
 	--32-bit			Scan 32-bit kernel.
 	--page-offset-32-bit=o		Page offset (for 32-bit kernel 0xABCD1234).
 	-d, --debug			Display debugging output.
-	-h, --help, --version		Display this help and exit.
+	-h, --help			Display this help and exit.
 
 Scans the running kernel for potential leaking addresses.
 
@@ -108,7 +108,6 @@ EOM
 GetOptions(
 	'd|debug'		=> \$debug,
 	'h|help'		=> \$help,
-	'version'		=> \$help,
 	'o|output-raw=s'        => \$output_raw,
 	'i|input-raw=s'         => \$input_raw,
 	'suppress-dmesg'        => \$suppress_dmesg,
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/3 leaking_addresses: Expand tilde in output file name

In reply to Tobin C. Harding

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Use perl function glob() to expand tilde in output file name.

---
 scripts/leaking_addresses.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/leaking_addresses.pl +1 -1
index ef9e5b2a1614..ce545ca3fb70 100755
@@ -150,7 +150,7 @@ if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) {
 }
 
 if ($output_raw) {
-	open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
+	open my $fh, '>', glob($output_raw) or die "$0: $output_raw: $!\n";
 	select $fh;
 }
 
Signature · 1 line
2.20.1
#4 lore raw

Re: [PATCH 3/3] leaking_addresses: Expand tilde in output file name

Quoted 15 lines · Tobin C. Harding

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Use perl function glob() to expand tilde in output file name.

---
 scripts/leaking_addresses.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/leaking_addresses.pl +0 -0
index ef9e5b2a1614..ce545ca3fb70 100755

scripts/leaking_addresses.pl if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) { · line 153

Quoted 5 lines
scripts/leaking_addresses.pl +1 -1
@@ -150,7 +150,7 @@ if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) {
 }
 
 if ($output_raw) {
-	open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
+	open my $fh, '>', glob($output_raw) or die "$0: $output_raw: $!\n";

Seems like you might also have the same problem with $input_raw? I wonder if you can just do this in GetOptions somehow, so that all users of these further down in the script don't have to remember to do this.

Cheers,

Tycho

#5 lore raw

Re: [PATCH 3/3] leaking_addresses: Expand tilde in output file name

Quoted 18 lines · Tycho Andersen
Quoted 17 lines · Tobin C. Harding

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Use perl function glob() to expand tilde in output file name.

---
 scripts/leaking_addresses.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/leaking_addresses.pl +0 -0
index ef9e5b2a1614..ce545ca3fb70 100755
@@ -150,7 +150,7 @@ if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) {
 }
 
Quoted 8 lines

scripts/leaking_addresses.pl if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) { · line 153

Quoted 3 lines
scripts/leaking_addresses.pl +1 -1
 if ($output_raw) {
-	open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
+	open my $fh, '>', glob($output_raw) or die "$0: $output_raw: $!\n";

Seems like you might also have the same problem with $input_raw? I wonder if you can just do this in GetOptions somehow, so that all users of these further down in the script don't have to remember to do this.

Thanks for the review, good idea - I'll look into it.

Tobin

#7 lore raw

RE: [PATCH 3/3] leaking_addresses: Expand tilde in output file name

In reply to Tobin C. Harding

From: Tobin C. Harding

Quoted 6 lines

Sent: 07 February 2019 22:50

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Use perl function glob() to expand tilde in output file name.

What happens if glob() returns multiple files?
I'm guessing that it can...

David

Quoted 19 lines
---
 scripts/leaking_addresses.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/leaking_addresses.pl +1 -2
index ef9e5b2a1614..ce545ca3fb70 100755
@@ -150,7 +150,7 @@ if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) {
 }
 
 if ($output_raw) {
-	open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
+	open my $fh, '>', glob($output_raw) or die "$0: $output_raw: $!\n";
 	select $fh;
 }
 
--
Quoted 1 line

2.20.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#8 lore raw

Re: [PATCH 3/3] leaking_addresses: Expand tilde in output file name

Quoted 10 lines · David Laight

From: Tobin C. Harding

Quoted 6 lines

Sent: 07 February 2019 22:50

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Use perl function glob() to expand tilde in output file name.

What happens if glob() returns multiple files?
I'm guessing that it can...

Thanks for taking a look at this David. Surely glob() cannot return multiple values when expanding tilde? If someone passes a '*' into the command as an input/output file then they are clearly mad :)

thanks,
Tobin.

#6 lore raw

Re: [PATCH 3/3] leaking_addresses: Expand tilde in output file name

In reply to Tycho Andersen
Quoted 18 lines · Tycho Andersen
Quoted 17 lines · Tobin C. Harding

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Use perl function glob() to expand tilde in output file name.

---
 scripts/leaking_addresses.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/leaking_addresses.pl +0 -0
index ef9e5b2a1614..ce545ca3fb70 100755
@@ -150,7 +150,7 @@ if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) {
 }
 
Quoted 8 lines

scripts/leaking_addresses.pl if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) { · line 153

Quoted 3 lines
scripts/leaking_addresses.pl +1 -1
 if ($output_raw) {
-	open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
+	open my $fh, '>', glob($output_raw) or die "$0: $output_raw: $!\n";

Seems like you might also have the same problem with $input_raw? I wonder if you can just do this in GetOptions somehow, so that all users of these further down in the script don't have to remember to do this.

I don't know what changed between now and when I first wrote this patch (a fair while ago) but I just tested with bash and zsh _without_ this patch and tilde was handled fine.

Dropping this patch, moving the other two onto leaks-next.

thanks,
Tobin.

#9 lore raw

RE: [PATCH 3/3] leaking_addresses: Expand tilde in output file name

In reply to Tobin C. Harding

From: Tobin C. Harding

Quoted 9 lines

Sent: 13 February 2019 20:31

Quoted 6 lines · David Laight

From: Tobin C. Harding

Quoted 5 lines

Sent: 07 February 2019 22:50

Currently if user passes an output file to the script via --output-raw we do not handle expansion of tilde.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Use perl function glob() to expand tilde in output file name.

What happens if glob() returns multiple files?
I'm guessing that it can...

Thanks for taking a look at this David. Surely glob() cannot return multiple values when expanding tilde? If someone passes a '*' into the command as an input/output file then they are clearly mad :)

Yes, but the perl script will go horribly wrong.

Actually, how do they get a ~ in there?
Whatever shell generated perl's argv[] would be expected to handle it.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)