Commit 27b6965a 27b6965a55e7b81eeb4029748b38f207fea75c2a by Sergey Poznyakoff

Fix coredump if crypt returns NULL.

* libmailutils/auth/system.c: Check return from crypt before passing it
to strcmp.
* libmu_auth/sql.c: Likewise.
1 parent baad4295
......@@ -100,12 +100,14 @@ mu_authenticate_generic (struct mu_auth_data **return_data MU_ARG_UNUSED,
{
const struct mu_auth_data *auth_data = key;
char *pass = call_data;
char *crypt_pass;
if (!auth_data || !pass)
return EINVAL;
return auth_data->passwd
&& strcmp (auth_data->passwd, crypt (pass, auth_data->passwd)) == 0 ?
return auth_data->passwd &&
(crypt_pass = crypt (pass, auth_data->passwd)) != NULL &&
strcmp (auth_data->passwd, crypt_pass) == 0 ?
0 : MU_ERR_AUTH_FAILURE;
}
......@@ -124,10 +126,13 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
if (auth_data)
{
struct spwd *spw;
char *crypt_pass;
spw = getspnam (auth_data->name);
if (spw)
return strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)) == 0 ?
0 : MU_ERR_AUTH_FAILURE;
return (crypt_pass = crypt (pass, spw->sp_pwdp)) != NULL &&
strcmp (spw->sp_pwdp, crypt_pass) == 0 ?
0 : MU_ERR_AUTH_FAILURE;
}
#endif
return MU_ERR_AUTH_FAILURE;
......
......@@ -627,7 +627,7 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
{
const struct mu_auth_data *auth_data = key;
char *pass = call_data;
char *sql_pass;
char *sql_pass, *crypt_pass;
int rc;
if (!auth_data)
......@@ -639,7 +639,11 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
switch (mu_sql_module_config.password_type)
{
case password_hash:
rc = strcmp (sql_pass, crypt (pass, sql_pass));
crypt_pass = crypt (pass, sql_pass);
if (!crypt_pass)
rc = 1;
else
rc = strcmp (sql_pass, crypt_pass);
break;
case password_scrambled:
......