Browse Source

Use new-style open calls everywhere: it's safer with weird filenames.

Raphael Hertzog 19 years ago
parent
commit
d3a5ca5a0f
4 changed files with 17 additions and 10 deletions
  1. 12 6
      scripts/dpkg-shlibdeps.pl
  2. 3 2
      scripts/modules/Objdump.pm
  3. 1 1
      scripts/modules/Shlibs.pm
  4. 1 1
      scripts/modules/SymbolFile.pm

+ 12 - 6
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:/ } (<OLD>)) {
 	    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 (<SHLIBS>) {
 	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 (<SYM_FILE>) {
 	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($_ = <DPKG>)) {
 	chomp($_);
 	if (m/^local diversion |^diversion by/) {

+ 3 - 2
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($_ = <OBJDUMP>)) {
@@ -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$/);

+ 1 - 1
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*$/;

+ 1 - 1
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($_ = <SYM_FILE>)) {
 	chomp($_);