1diff --git a/tools/c_rehash.in b/tools/c_rehash.in 2index fa7c6c9fef..83c1cc80e0 100644 3--- a/tools/c_rehash.in 4+++ b/tools/c_rehash.in 5@@ -152,6 +152,23 @@ sub check_file { 6 return ($is_cert, $is_crl); 7 } 8 9+sub compute_hash { 10+ my $fh; 11+ if ( $^O eq "VMS" ) { 12+ # VMS uses the open through shell 13+ # The file names are safe there and list form is unsupported 14+ if (!open($fh, "-|", join(' ', @_))) { 15+ print STDERR "Cannot compute hash on '$fname'\n"; 16+ return; 17+ } 18+ } else { 19+ if (!open($fh, "-|", @_)) { 20+ print STDERR "Cannot compute hash on '$fname'\n"; 21+ return; 22+ } 23+ } 24+ return (<$fh>, <$fh>); 25+} 26 27 # Link a certificate to its subject name hash value, each hash is of 28 # the form <hash>.<n> where n is an integer. If the hash value already exists 29@@ -161,10 +178,12 @@ sub check_file { 30 31 sub link_hash_cert { 32 my $fname = $_[0]; 33- $fname =~ s/\"/\\\"/g; 34- my ($hash, $fprint) = `"$openssl" x509 $x509hash -fingerprint -noout -in "$fname"`; 35+ my ($hash, $fprint) = compute_hash($openssl, "x509", $x509hash, 36+ "-fingerprint", "-noout", 37+ "-in", $fname); 38 chomp $hash; 39 chomp $fprint; 40+ return if !$hash; 41 $fprint =~ s/^.*=//; 42 $fprint =~ tr/://d; 43 my $suffix = 0; 44@@ -202,10 +221,12 @@ sub link_hash_cert { 45 46 sub link_hash_crl { 47 my $fname = $_[0]; 48- $fname =~ s/'/'\\''/g; 49- my ($hash, $fprint) = `"$openssl" crl $crlhash -fingerprint -noout -in '$fname'`; 50+ my ($hash, $fprint) = compute_hash($openssl, "crl", $crlhash, 51+ "-fingerprint", "-noout", 52+ "-in", $fname); 53 chomp $hash; 54 chomp $fprint; 55+ return if !$hash; 56 $fprint =~ s/^.*=//; 57 $fprint =~ tr/://d; 58 my $suffix = 0;