Commit d94024ffc7 for openssl.org

commit d94024ffc7e726566a6255228ad0a7de4cfc956d
Author: Martin Mirchev <mirchevmartin2203@gmail.com>
Date:   Thu Oct 22 10:15:19 2026 +0800

    apps/passwd.c: fail when the password hash cannot be computed

    shacrypt() returns NULL for a salt that starts with "rounds=" but has
    no '$' after the number, e.g. "openssl passwd -5 -salt rounds=xyz".
    do_passwd() only asserted that the hash was not NULL, so in release
    builds it printed "(null)" as the hash and the command exited
    with status 0.

    Report an error and fail instead, and add tests for -5 and -6.

    Assisted-by: Claude:claude-opus-5-5
    Reviewed-by: Richard Levitte <levitte@openssl.foundation>
    Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
    Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
    Merge-date: Wed Nov 25 16:14:39 2026
    Merged-from: https://github.com/openssl/openssl/pull/33313

diff --git a/apps/passwd.c b/apps/passwd.c
index a2fff324aa..c909a91251 100644
--- a/apps/passwd.c
+++ b/apps/passwd.c
@@ -837,7 +837,10 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
         hash = md5crypt(passwd, "", *salt_p);
     if (mode == passwd_sha256 || mode == passwd_sha512)
         hash = shacrypt(passwd, (mode == passwd_sha256 ? "5" : "6"), *salt_p);
-    assert(hash != NULL);
+    if (hash == NULL) {
+        BIO_printf(bio_err, "Error computing password hash\n");
+        goto end;
+    }

     if (table && !reverse)
         BIO_printf(out, "%s\t%s\n", passwd, hash);
diff --git a/test/recipes/20-test_passwd.t b/test/recipes/20-test_passwd.t
index bd2a2ae469..858428592f 100644
--- a/test/recipes/20-test_passwd.t
+++ b/test/recipes/20-test_passwd.t
@@ -80,7 +80,7 @@ my @sha_high_rounds_tests =
        expected => '$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwcelCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1' },
     );

-plan tests => 9 + scalar @sha_tests + scalar @sha_high_rounds_tests;
+plan tests => 11 + scalar @sha_tests + scalar @sha_high_rounds_tests;


 ok(compare1stline_re([qw{openssl passwd -1 password}], '^\$1\$.{8}\$.{22}\R$'),
@@ -103,6 +103,12 @@ ok(compare1stline([qw{openssl passwd -salt xxxxxxxxxxxxxxxx -5 password}], '$5$x
 ok(compare1stline([qw{openssl passwd -salt xxxxxxxxxxxxxxxx -6 password}], '$6$xxxxxxxxxxxxxxxx$VjGUrXBG6/8yW0f6ikBJVOb/lK/Tm9LxHJmFfwMvT7cpk64N9BW7ZQhNeMXAYFbOJ6HDG7wb0QpxJyYQn0rh81'),
    'SHA512 password with salt xxxxxxxxxxxxxxxx');

+# A "rounds=" prefix without the terminating '$' is not a valid salt
+ok(!run(app([qw{openssl passwd -5 -salt rounds=xyz password}])),
+   'SHA256 password with invalid rounds salt fails');
+ok(!run(app([qw{openssl passwd -6 -salt rounds=xyz password}])),
+   'SHA512 password with invalid rounds salt fails');
+
 foreach (@sha_tests) {
     ok(compare1stline([qw{openssl passwd}, '-'.$_->{type}, '-salt', $_->{salt},
                        $_->{key}], $_->{expected}),