The behavior of these functions upon errors depends on the implementation.
The GNU libc implementation seems to return a null hash, but others like
libxcrypt returns a invalid hash string '*0'.
Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
* Relies on the assertion that cleartext_utf8->data is a zero
* terminated UTF-8 string
*/
+ errno = 0;
#ifdef HAVE_CRYPT_R
hash = crypt_r((char *)io->n.cleartext_utf8->data, cmd, &crypt_data);
#else
*/
hash = crypt((char *)io->n.cleartext_utf8->data, cmd);
#endif
- if (hash == NULL) {
+ /* crypt_r and crypt may return a null pointer upon error depending on
+ * how libcrypt was configured. POSIX specifies returning a null
+ * pointer and setting errno. */
+ if (hash == NULL || errno != 0) {
char buf[1024];
int err = strerror_r(errno, buf, sizeof(buf));
if (err != 0) {