c59d11
From 5984f005f7a08feca52509658cff1c56d768e057 Mon Sep 17 00:00:00 2001
c59d11
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
c59d11
Date: Mon, 1 Dec 2014 15:28:36 +0100
c59d11
Subject: [PATCH] t/op/taint.t: Perform SHA-256 algorithm by crypt() if default
c59d11
 one is disabled
c59d11
MIME-Version: 1.0
c59d11
Content-Type: text/plain; charset=UTF-8
c59d11
Content-Transfer-Encoding: 8bit
c59d11
c59d11
The crypt(3) call may return NULL. This is the case on FIPS-enabled
c59d11
platforms. Then "tainted crypt" test would fail.
c59d11
c59d11
See RT#121591 for similar fix in t/op/crypt.t.
c59d11
c59d11
Signed-off-by: Petr Písař <ppisar@redhat.com>
c59d11
c59d11
Petr Pisar: Ported to 5.16.3.
c59d11
c59d11
Signed-off-by: Petr Písař <ppisar@redhat.com>
c59d11
---
c59d11
 t/op/taint.t | 14 +++++++++++++-
c59d11
 1 file changed, 13 insertions(+), 1 deletion(-)
c59d11
c59d11
diff --git a/t/op/taint.t b/t/op/taint.t
c59d11
index 9cea740..478e574 100644
c59d11
--- a/t/op/taint.t
c59d11
+++ b/t/op/taint.t
c59d11
@@ -1868,7 +1868,19 @@ foreach my $ord (78, 163, 256) {
c59d11
 
c59d11
 {
c59d11
     # 59998
c59d11
-    sub cr { my $x = crypt($_[0], $_[1]); $x }
c59d11
+    sub cr {
c59d11
+        # On platforms implementing FIPS mode, using a weak algorithm
c59d11
+        # (including the default triple-DES algorithm) causes crypt(3) to
c59d11
+        # return a null pointer, which Perl converts into undef. We assume
c59d11
+        # for now that all such platforms support glibc-style selection of
c59d11
+        # a different hashing algorithm.
c59d11
+        my $alg = '';       # Use default algorithm
c59d11
+        if ( !defined(crypt("ab", "cd")) ) {
c59d11
+            $alg = '$5$';   # Use SHA-256
c59d11
+        }
c59d11
+        my $x = crypt($_[0], $alg . $_[1]);
c59d11
+        $x
c59d11
+    }
c59d11
     sub co { my $x = ~$_[0]; $x }
c59d11
     my ($a, $b);
c59d11
     $a = cr('hello', 'foo' . $TAINT);
c59d11
-- 
c59d11
1.9.3
c59d11