Hi,

crypt_newhash(3) will return -1 and set errno to EINVAL if hashsize is
too small to accommodate bcrypt's hash space.  I imagine this would
also be the case if anything other than bcrypt were supported.

Test program:

#include <err.h>
#include <string.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
        char buf[20], hash1[61], hash2[60];

        memset(buf, 'a', sizeof(buf));
        buf[sizeof(buf) - 1] = '\0';
        if (crypt_newhash(buf, "bcrypt,a", hash1, sizeof(hash1)) == -1)
                err(1, "crypt_newhash 1");
        if (crypt_newhash(buf, "bcrypt,a", hash2, sizeof(hash2)) == -1)
                err(1, "crypt_newhash 2");
        return 0;
}

Attached patch documents the case.

--
Scott Cheloha

Index: lib/libc/crypt/crypt_checkpass.3
===================================================================
RCS file: /cvs/src/lib/libc/crypt/crypt_checkpass.3,v
retrieving revision 1.9
diff -u -p -r1.9 crypt_checkpass.3
--- lib/libc/crypt/crypt_checkpass.3    23 Jul 2015 22:20:02 -0000      1.9
+++ lib/libc/crypt/crypt_checkpass.3    21 Jul 2017 22:33:51 -0000
@@ -89,7 +89,12 @@ to
 .Er EINVAL
 if
 .Fa pref
-is unsupported.
+is unsupported,
+or if
+.Fa pref Ns 's
+hash space exceeds
+.Fa hashsize
+bytes.
 .Sh SEE ALSO
 .Xr crypt 3 ,
 .Xr login.conf 5 ,

Reply via email to