From d3a5ca5a0f3d79c32d3a410501382686cc2f57e6 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Mon, 2 Jul 2007 13:26:01 +0000 Subject: [PATCH] Use new-style open calls everywhere: it's safer with weird filenames. --- scripts/dpkg-shlibdeps.pl | 18 ++++++++++++------ scripts/modules/Objdump.pm | 5 +++-- scripts/modules/Shlibs.pm | 2 +- scripts/modules/SymbolFile.pm | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl index 3c097b59..10a1bf22 100755 --- a/scripts/dpkg-shlibdeps.pl +++ b/scripts/dpkg-shlibdeps.pl @@ -202,10 +202,10 @@ my $fh; if ($stdout) { $fh = \*STDOUT; } else { - open(NEW,"> $varlistfile.new") || + open(NEW, ">", "$varlistfile.new") || syserr(sprintf(_g("open new substvars file \`%s'"), "$varlistfile.new")); if (-e $varlistfile) { - open(OLD,"< $varlistfile") || + open(OLD, "<", $varlistfile) || syserr(sprintf(_g("open old varlist file \`%s' for reading"), $varlistfile)); foreach my $entry (grep { not /^\Q$varnameprefix\E:/ } ()) { print(NEW $entry) || @@ -336,7 +336,7 @@ sub extract_from_shlibs { } # Open shlibs file $shlibfile = "./$shlibfile" if $shlibfile =~ m/^\s/; - open(SHLIBS, "< $shlibfile") || syserr(sprintf(_g("unable to open shared libs info file \`%s'"), $shlibfile)); + open(SHLIBS, "<", $shlibfile) || syserr(sprintf(_g("unable to open shared libs info file \`%s'"), $shlibfile)); my $dep; while () { s/\s*\n$//; next if m/^\#/; @@ -371,7 +371,7 @@ sub find_symbols_file { sub symfile_has_soname { my ($file, $soname) = @_; - open(SYM_FILE, "< $file") || syserr("can't open file $file"); + open(SYM_FILE, "<", $file) || syserr("can't open file $file"); my $result = 0; while () { if (/^\Q$soname\E /) { @@ -403,8 +403,14 @@ sub my_find_library { sub find_packages { my @files = (@_); my $pkgmatch = {}; - open(DPKG, "dpkg --search -- @files 2>/dev/null |") || - syserr(sprintf(_g("Can't execute dpkg --search: %s"), $!)); + my $pid = open(DPKG, "-|") || syserr(_g("cannot fork for dpkg --search"));; + if (!$pid) { + # Child process running dpkg --search and discarding errors + close STDERR; + open STDERR, ">", "/dev/null"; + $ENV{LC_ALL} = "C"; + exec("dpkg", "--search", "--", @files) or syserr(_g("cannot exec dpkg"));; + } while(defined($_ = )) { chomp($_); if (m/^local diversion |^diversion by/) { diff --git a/scripts/modules/Objdump.pm b/scripts/modules/Objdump.pm index da93f821..15d62464 100644 --- a/scripts/modules/Objdump.pm +++ b/scripts/modules/Objdump.pm @@ -13,7 +13,8 @@ sub new { sub parse { my ($self, $file) = @_; local $ENV{LC_ALL} = 'C'; - open(OBJDUMP, "objdump -w -p -T $file |") || syserr(sprintf(_g("Can't execute objdump: %s"), $!)); + open(OBJDUMP, "-|", "objdump", "-w", "-p", "-T", $file) || + syserr(sprintf(_g("Can't execute objdump: %s"), $!)); my $obj = Dpkg::Shlibs::Objdump::Object->new($file); my $section = "none"; while (defined($_ = )) { @@ -171,7 +172,7 @@ sub get_object { sub is_elf { my ($file) = @_; - open(FILE, "< $file") || main::syserr(sprintf(_g("Can't open %s for test: %s"), $file, $!)); + open(FILE, "<", $file) || main::syserr(sprintf(_g("Can't open %s for test: %s"), $file, $!)); my ($header, $result) = ("", 0); if (read(FILE, $header, 4) == 4) { $result = 1 if ($header =~ /^\177ELF$/); diff --git a/scripts/modules/Shlibs.pm b/scripts/modules/Shlibs.pm index f029933a..2af75ac6 100644 --- a/scripts/modules/Shlibs.pm +++ b/scripts/modules/Shlibs.pm @@ -29,7 +29,7 @@ parse_ldso_conf("/etc/ld.so.conf") if -e "/etc/ld.so.conf"; sub parse_ldso_conf { my $file = shift; my $fh = new IO::File; - $fh->open("< $file") + $fh->open($file, "<") or main::syserr(sprintf(_g("couldn't open %s: %s"), $file, $!)); while (<$fh>) { next if /^\s*$/; diff --git a/scripts/modules/SymbolFile.pm b/scripts/modules/SymbolFile.pm index ccec332b..ec3bf6a1 100644 --- a/scripts/modules/SymbolFile.pm +++ b/scripts/modules/SymbolFile.pm @@ -34,7 +34,7 @@ sub clear_except { sub load { my ($self, $file) = @_; $self->{file} = $file; - open(SYM_FILE, "< $file") || main::syserr(sprintf(_g("Can't open %s: %s"), $file)); + open(SYM_FILE, "<", $file) || main::syserr(sprintf(_g("Can't open %s: %s"), $file)); my ($object); while (defined($_ = )) { chomp($_); -- 2.39.5