520-loginutils-handle-crypt-failures.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --- a/loginutils/chpasswd.c
  2. +++ b/loginutils/chpasswd.c
  3. @@ -97,6 +97,11 @@ int chpasswd_main(int argc UNUSED_PARAM,
  4. crypt_make_pw_salt(salt, algo);
  5. free_me = pass = pw_encrypt(pass, salt, 0);
  6. +
  7. + if (pass[0] == 0) {
  8. + free(free_me);
  9. + bb_perror_msg_and_die("password encryption failed");
  10. + }
  11. }
  12. /* This is rather complex: if user is not found in /etc/shadow,
  13. --- a/loginutils/cryptpw.c
  14. +++ b/loginutils/cryptpw.c
  15. @@ -95,7 +95,7 @@ int cryptpw_main(int argc UNUSED_PARAM,
  16. /* Supports: cryptpw -m sha256 PASS 'rounds=999999999$SALT' */
  17. char salt[MAX_PW_SALT_LEN + sizeof("rounds=999999999$")];
  18. char *salt_ptr;
  19. - char *password;
  20. + char *password, *hash;
  21. const char *opt_m, *opt_S;
  22. int fd;
  23. @@ -140,8 +140,12 @@ int cryptpw_main(int argc UNUSED_PARAM,
  24. /* may still be NULL on EOF/error */
  25. }
  26. - if (password)
  27. - puts(pw_encrypt(password, salt, 1));
  28. + if (password) {
  29. + hash = pw_encrypt(password, salt, 1);
  30. + if (hash[0] == 0)
  31. + bb_perror_msg_and_die("password encryption failed");
  32. + puts(hash);
  33. + }
  34. return EXIT_SUCCESS;
  35. }
  36. --- a/loginutils/passwd.c
  37. +++ b/loginutils/passwd.c
  38. @@ -187,6 +187,10 @@ int passwd_main(int argc UNUSED_PARAM, c
  39. if (!newp) {
  40. logmode = LOGMODE_STDIO;
  41. bb_error_msg_and_die("password for %s is unchanged", name);
  42. + } else if (newp[0] == 0) {
  43. + logmode = LOGMODE_STDIO;
  44. + free(newp);
  45. + bb_perror_msg_and_die("password encryption failed");
  46. }
  47. } else if (opt & OPT_lock) {
  48. if (!c)