logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

shadow-4.9-SHA-rounds.patch (1714B)


  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. If SHA_CRYPT_MIN_ROUNDS and SHA_CRYPT_MAX_ROUNDS are both unspecified,
  6. use SHA_ROUNDS_DEFAULT.
  7. Previously, the code fell through, calling shadow_random(-1, -1). This
  8. ultimately set rounds = (unsigned long) -1, which ends up being a very
  9. large number! This then got capped to SHA_ROUNDS_MAX later in the
  10. function.
  11. The new behavior matches BCRYPT_get_salt_rounds().
  12. Bug: https://bugs.gentoo.org/808195
  13. Fixes: https://github.com/shadow-maint/shadow/issues/393
  14. ---
  15. libmisc/salt.c | 21 +++++++++++----------
  16. 1 file changed, 11 insertions(+), 10 deletions(-)
  17. diff --git a/libmisc/salt.c b/libmisc/salt.c
  18. index 91d528fd..30eefb9c 100644
  19. --- a/libmisc/salt.c
  20. +++ b/libmisc/salt.c
  21. @@ -223,20 +223,21 @@ static /*@observer@*/const unsigned long SHA_get_salt_rounds (/*@null@*/int *pre
  22. if ((-1 == min_rounds) && (-1 == max_rounds)) {
  23. rounds = SHA_ROUNDS_DEFAULT;
  24. }
  25. + else {
  26. + if (-1 == min_rounds) {
  27. + min_rounds = max_rounds;
  28. + }
  29. - if (-1 == min_rounds) {
  30. - min_rounds = max_rounds;
  31. - }
  32. + if (-1 == max_rounds) {
  33. + max_rounds = min_rounds;
  34. + }
  35. - if (-1 == max_rounds) {
  36. - max_rounds = min_rounds;
  37. - }
  38. + if (min_rounds > max_rounds) {
  39. + max_rounds = min_rounds;
  40. + }
  41. - if (min_rounds > max_rounds) {
  42. - max_rounds = min_rounds;
  43. + rounds = (unsigned long) shadow_random (min_rounds, max_rounds);
  44. }
  45. -
  46. - rounds = (unsigned long) shadow_random (min_rounds, max_rounds);
  47. } else if (0 == *prefered_rounds) {
  48. rounds = SHA_ROUNDS_DEFAULT;
  49. } else {