]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/libcrypt-util: do not refuse passwords if some other hash is unsupported
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Sep 2020 06:27:43 +0000 (08:27 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Sep 2020 09:52:30 +0000 (11:52 +0200)
src/shared/libcrypt-util.c
src/test/test-libcrypt-util.c

index 66f345ee5f7cb228e8279ce081ed168cc12176dd..c5d98671bd6d672f49c1fd9398e245fae4c9f254 100644 (file)
@@ -182,8 +182,12 @@ int test_password_one(const char *hashed_password, const char *password) {
 
         errno = 0;
         k = crypt_ra(password, hashed_password, &cd_data, &cd_size);
-        if (!k)
-                return errno_or_else(EINVAL);
+        if (!k) {
+                if (errno == ENOMEM)
+                        return -ENOMEM;
+                /* Unknown or unavailable hashing method or string too short */
+                return 0;
+        }
 
         return streq(k, hashed_password);
 }
index 90abfa7b81e98b710bfdd849d2cc12c968e2223d..1c570784f4e4d918328ac1ae4de65f800b10abcc 100644 (file)
@@ -40,10 +40,18 @@ static void test_hash_password_full(void) {
                                                                hashed,
                                                                "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
                                                      i) == true);
+                        assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
+                                                               hashed,
+                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
+                                                     i) == true);
                         assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
                                                                hashed,
                                                                "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
                                                      "") == false);
+                        assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
+                                                               hashed,
+                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
+                                                     "") == false);
                 }
 }