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