Skip to content

Commit 158d6fd

Browse files
committed
Fix segfault when crypt() returns NULL
`crypt()` and `crypt_r()` can return `NULL` when an error is encountered. For example, if a user has been locked using `usermod -L`, queries to the password database can return an encrypted password prefixed by `!`, and `crypt()` will return `NULL` because the password hash is malformed. This change prevents `auth_password_compare_pwd()` from dereferencing a NULL pointer if `crypt()` or `crypt_r()` returns NULL due to an error. Instead, we now return nonzero in this case (i.e., authentication failed).
1 parent db2933f commit 158d6fd

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/session_server_ssh.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,11 @@ auth_password_compare_pwd(const char *pass_hash, const char *pass_clear)
787787
new_pass_hash = crypt(pass_clear, pass_hash);
788788
pthread_mutex_unlock(&crypt_lock);
789789
#endif
790+
791+
if (!new_pass_hash) {
792+
return 1;
793+
}
794+
790795
return strcmp(new_pass_hash, pass_hash);
791796
}
792797

0 commit comments

Comments
 (0)