Blame SOURCES/openssl-1.1.1-cve-2022-1292.patch

eaef03
From e5fd1728ef4c7a5bf7c7a7163ca60370460a6e23 Mon Sep 17 00:00:00 2001
eaef03
From: Tomas Mraz <tomas@openssl.org>
eaef03
Date: Tue, 26 Apr 2022 12:40:24 +0200
eaef03
Subject: [PATCH] c_rehash: Do not use shell to invoke openssl
eaef03
eaef03
Except on VMS where it is safe.
eaef03
eaef03
This fixes CVE-2022-1292.
eaef03
eaef03
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
eaef03
Reviewed-by: Matt Caswell <matt@openssl.org>
eaef03
Upstream-Status: Backport [https://github.com/openssl/openssl/commit/e5fd1728ef4c7a5bf7c7a7163ca60370460a6e23]
eaef03
---
eaef03
 tools/c_rehash.in | 29 +++++++++++++++++++++++++----
eaef03
 1 file changed, 25 insertions(+), 4 deletions(-)
eaef03
eaef03
diff --git a/tools/c_rehash.in b/tools/c_rehash.in
eaef03
index fa7c6c9fef91..83c1cc80e08a 100644
eaef03
--- a/tools/c_rehash.in
eaef03
+++ b/tools/c_rehash.in
eaef03
@@ -152,6 +152,23 @@ sub check_file {
eaef03
 	return ($is_cert, $is_crl);
eaef03
 }
eaef03
 
eaef03
+sub compute_hash {
eaef03
+    my $fh;
eaef03
+    if ( $^O eq "VMS" ) {
eaef03
+        # VMS uses the open through shell
eaef03
+        # The file names are safe there and list form is unsupported
eaef03
+        if (!open($fh, "-|", join(' ', @_))) {
eaef03
+            print STDERR "Cannot compute hash on '$fname'\n";
eaef03
+            return;
eaef03
+        }
eaef03
+    } else {
eaef03
+        if (!open($fh, "-|", @_)) {
eaef03
+            print STDERR "Cannot compute hash on '$fname'\n";
eaef03
+            return;
eaef03
+        }
eaef03
+    }
eaef03
+    return (<$fh>, <$fh>);
eaef03
+}
eaef03
 
eaef03
 # Link a certificate to its subject name hash value, each hash is of
eaef03
 # the form <hash>.<n> where n is an integer. If the hash value already exists
eaef03
@@ -161,10 +178,12 @@ sub check_file {
eaef03
 
eaef03
 sub link_hash_cert {
eaef03
 		my $fname = $_[0];
eaef03
-		$fname =~ s/\"/\\\"/g;
eaef03
-		my ($hash, $fprint) = `"$openssl" x509 $x509hash -fingerprint -noout -in "$fname"`;
eaef03
+		my ($hash, $fprint) = compute_hash($openssl, "x509", $x509hash,
eaef03
+						   "-fingerprint", "-noout",
eaef03
+						   "-in", $fname);
eaef03
 		chomp $hash;
eaef03
 		chomp $fprint;
eaef03
+		return if !$hash;
eaef03
 		$fprint =~ s/^.*=//;
eaef03
 		$fprint =~ tr/://d;
eaef03
 		my $suffix = 0;
eaef03
@@ -202,10 +221,12 @@ sub link_hash_cert {
eaef03
 
eaef03
 sub link_hash_crl {
eaef03
 		my $fname = $_[0];
eaef03
-		$fname =~ s/'/'\\''/g;
eaef03
-		my ($hash, $fprint) = `"$openssl" crl $crlhash -fingerprint -noout -in '$fname'`;
eaef03
+		my ($hash, $fprint) = compute_hash($openssl, "crl", $crlhash,
eaef03
+						   "-fingerprint", "-noout",
eaef03
+						   "-in", $fname);
eaef03
 		chomp $hash;
eaef03
 		chomp $fprint;
eaef03
+		return if !$hash;
eaef03
 		$fprint =~ s/^.*=//;
eaef03
 		$fprint =~ tr/://d;
eaef03
 		my $suffix = 0;