Skip to content

Commit 1b1bcbf

Browse files
committed
leaking_addresses: Use File::Temp for /tmp files
Instead of using a statically named path in /tmp, use File::Temp to create (and remove) the temporary file used for parsing /proc/config.gz. Reviewed-by: Tycho Andersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 616cfbf commit 1b1bcbf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

scripts/leaking_addresses.pl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use POSIX;
2424
use File::Basename;
2525
use File::Spec;
26+
use File::Temp qw/tempfile/;
2627
use Cwd 'abs_path';
2728
use Term::ANSIColor qw(:constants);
2829
use Getopt::Long qw(:config no_auto_abbrev);
@@ -221,14 +222,16 @@ sub get_kernel_config_option
221222
{
222223
my ($option) = @_;
223224
my $value = "";
225+
my $tmp_fh;
224226
my $tmp_file = "";
225227
my @config_files;
226228

227229
# Allow --kernel-config-file to override.
228230
if ($kernel_config_file ne "") {
229231
@config_files = ($kernel_config_file);
230232
} elsif (-R "/proc/config.gz") {
231-
my $tmp_file = "/tmp/tmpkconf";
233+
($tmp_fh, $tmp_file) = tempfile("config.gz-XXXXXX",
234+
UNLINK => 1);
232235

233236
if (system("gunzip < /proc/config.gz > $tmp_file")) {
234237
dprint("system(gunzip < /proc/config.gz) failed\n");
@@ -250,10 +253,6 @@ sub get_kernel_config_option
250253
}
251254
}
252255

253-
if ($tmp_file ne "") {
254-
system("rm -f $tmp_file");
255-
}
256-
257256
return $value;
258257
}
259258

0 commit comments

Comments
 (0)