Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame^] | 1 | From 234e8fa7b134d1ebabfdad980a3ae5b63c046c62 Mon Sep 17 00:00:00 2001 |
| 2 | From: Mike Gilbert <floppym@gentoo.org> |
| 3 | Date: Sat, 14 Aug 2021 13:24:34 -0400 |
| 4 | Subject: [PATCH] libmisc: fix default value in SHA_get_salt_rounds() |
| 5 | |
| 6 | If SHA_CRYPT_MIN_ROUNDS and SHA_CRYPT_MAX_ROUNDS are both unspecified, |
| 7 | use SHA_ROUNDS_DEFAULT. |
| 8 | |
| 9 | Previously, the code fell through, calling shadow_random(-1, -1). This |
| 10 | ultimately set rounds = (unsigned long) -1, which ends up being a very |
| 11 | large number! This then got capped to SHA_ROUNDS_MAX later in the |
| 12 | function. |
| 13 | |
| 14 | The new behavior matches BCRYPT_get_salt_rounds(). |
| 15 | |
| 16 | Bug: https://bugs.gentoo.org/808195 |
| 17 | Fixes: https://github.com/shadow-maint/shadow/issues/393 |
| 18 | |
| 19 | Upstream-Status: Backport [https://github.com/shadow-maint/shadow/commit/234e8fa7b134d1ebabfdad980a3ae5b63c046c62] |
| 20 | |
| 21 | Signed-off-by: Mingli Yu <mingli.yu@windriver.com> |
| 22 | --- |
| 23 | libmisc/salt.c | 21 +++++++++++---------- |
| 24 | 1 file changed, 11 insertions(+), 10 deletions(-) |
| 25 | |
| 26 | diff --git a/libmisc/salt.c b/libmisc/salt.c |
| 27 | index 91d528fd..30eefb9c 100644 |
| 28 | --- a/libmisc/salt.c |
| 29 | +++ b/libmisc/salt.c |
| 30 | @@ -223,20 +223,21 @@ static /*@observer@*/const unsigned long SHA_get_salt_rounds (/*@null@*/int *pre |
| 31 | if ((-1 == min_rounds) && (-1 == max_rounds)) { |
| 32 | rounds = SHA_ROUNDS_DEFAULT; |
| 33 | } |
| 34 | + else { |
| 35 | + if (-1 == min_rounds) { |
| 36 | + min_rounds = max_rounds; |
| 37 | + } |
| 38 | |
| 39 | - if (-1 == min_rounds) { |
| 40 | - min_rounds = max_rounds; |
| 41 | - } |
| 42 | + if (-1 == max_rounds) { |
| 43 | + max_rounds = min_rounds; |
| 44 | + } |
| 45 | |
| 46 | - if (-1 == max_rounds) { |
| 47 | - max_rounds = min_rounds; |
| 48 | - } |
| 49 | + if (min_rounds > max_rounds) { |
| 50 | + max_rounds = min_rounds; |
| 51 | + } |
| 52 | |
| 53 | - if (min_rounds > max_rounds) { |
| 54 | - max_rounds = min_rounds; |
| 55 | + rounds = (unsigned long) shadow_random (min_rounds, max_rounds); |
| 56 | } |
| 57 | - |
| 58 | - rounds = (unsigned long) shadow_random (min_rounds, max_rounds); |
| 59 | } else if (0 == *prefered_rounds) { |
| 60 | rounds = SHA_ROUNDS_DEFAULT; |
| 61 | } else { |
| 62 | -- |
| 63 | 2.17.1 |
| 64 | |