Blame SOURCES/shadow-4.9-libmisc-fix-default-value-in-SHA_get_salt_rounds.patch

b8f1b8
From 234e8fa7b134d1ebabfdad980a3ae5b63c046c62 Mon Sep 17 00:00:00 2001
b8f1b8
From: Mike Gilbert <floppym@gentoo.org>
b8f1b8
Date: Sat, 14 Aug 2021 13:24:34 -0400
b8f1b8
Subject: [PATCH] libmisc: fix default value in SHA_get_salt_rounds()
b8f1b8
b8f1b8
If SHA_CRYPT_MIN_ROUNDS and SHA_CRYPT_MAX_ROUNDS are both unspecified,
b8f1b8
use SHA_ROUNDS_DEFAULT.
b8f1b8
b8f1b8
Previously, the code fell through, calling shadow_random(-1, -1). This
b8f1b8
ultimately set rounds = (unsigned long) -1, which ends up being a very
b8f1b8
large number! This then got capped to SHA_ROUNDS_MAX later in the
b8f1b8
function.
b8f1b8
b8f1b8
The new behavior matches BCRYPT_get_salt_rounds().
b8f1b8
b8f1b8
Bug: https://bugs.gentoo.org/808195
b8f1b8
Fixes: https://github.com/shadow-maint/shadow/issues/393
b8f1b8
---
b8f1b8
 libmisc/salt.c | 21 +++++++++++----------
b8f1b8
 1 file changed, 11 insertions(+), 10 deletions(-)
b8f1b8
b8f1b8
diff --git a/libmisc/salt.c b/libmisc/salt.c
b8f1b8
index 91d528fd..30eefb9c 100644
b8f1b8
--- a/libmisc/salt.c
b8f1b8
+++ b/libmisc/salt.c
b8f1b8
@@ -223,20 +223,21 @@ static /*@observer@*/const unsigned long SHA_get_salt_rounds (/*@null@*/int *pre
b8f1b8
 		if ((-1 == min_rounds) && (-1 == max_rounds)) {
b8f1b8
 			rounds = SHA_ROUNDS_DEFAULT;
b8f1b8
 		}
b8f1b8
+		else {
b8f1b8
+			if (-1 == min_rounds) {
b8f1b8
+				min_rounds = max_rounds;
b8f1b8
+			}
b8f1b8
 
b8f1b8
-		if (-1 == min_rounds) {
b8f1b8
-			min_rounds = max_rounds;
b8f1b8
-		}
b8f1b8
+			if (-1 == max_rounds) {
b8f1b8
+				max_rounds = min_rounds;
b8f1b8
+			}
b8f1b8
 
b8f1b8
-		if (-1 == max_rounds) {
b8f1b8
-			max_rounds = min_rounds;
b8f1b8
-		}
b8f1b8
+			if (min_rounds > max_rounds) {
b8f1b8
+				max_rounds = min_rounds;
b8f1b8
+			}
b8f1b8
 
b8f1b8
-		if (min_rounds > max_rounds) {
b8f1b8
-			max_rounds = min_rounds;
b8f1b8
+			rounds = (unsigned long) shadow_random (min_rounds, max_rounds);
b8f1b8
 		}
b8f1b8
-
b8f1b8
-		rounds = (unsigned long) shadow_random (min_rounds, max_rounds);
b8f1b8
 	} else if (0 == *prefered_rounds) {
b8f1b8
 		rounds = SHA_ROUNDS_DEFAULT;
b8f1b8
 	} else {
b8f1b8
-- 
b8f1b8
2.31.1
b8f1b8