Skip to content

Commit

Permalink
conn: don't crash when user sets password to NULL
Browse files Browse the repository at this point in the history
Make it possible to reset password to NULL. It is not required for
ANONYMOUS authentication. Also, report an error and disconnect if
password is not set and libstrophe should try authentication mechanisms
other than ANONYMOUS.
  • Loading branch information
pasis committed Sep 30, 2020
1 parent 60ce94c commit c07ac0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ static void _auth(xmpp_conn_t *const conn)
xmpp_error(conn->ctx, "auth",
"No node in JID, and SASL ANONYMOUS unsupported.");
xmpp_disconnect(conn);
} else if (conn->pass == NULL) {
xmpp_error(conn->ctx, "auth",
"Password hasn't been set, and SASL ANONYMOUS unsupported.");
xmpp_disconnect(conn);
} else if (conn->sasl_support & SASL_MASK_SCRAM) {
scram_ctx = xmpp_alloc(conn->ctx, sizeof(*scram_ctx));
if (conn->sasl_support & SASL_MASK_SCRAMSHA512)
Expand Down
2 changes: 1 addition & 1 deletion src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void xmpp_conn_set_pass(xmpp_conn_t *const conn, const char *const pass)
{
if (conn->pass)
xmpp_free(conn->ctx, conn->pass);
conn->pass = xmpp_strdup(conn->ctx, pass);
conn->pass = pass ? xmpp_strdup(conn->ctx, pass) : NULL;
}

/** Get the strophe context that the connection is associated with.
Expand Down

0 comments on commit c07ac0a

Please sign in to comment.