From c07ac0a68d08538c20dba296f44b0c56f68738ad Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 30 Sep 2020 20:56:52 +0300 Subject: [PATCH] conn: don't crash when user sets password to NULL 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. --- src/auth.c | 4 ++++ src/conn.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/auth.c b/src/auth.c index 5ad7e29..c60512b 100644 --- a/src/auth.c +++ b/src/auth.c @@ -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) diff --git a/src/conn.c b/src/conn.c index 9c145bf..e6b4411 100644 --- a/src/conn.c +++ b/src/conn.c @@ -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.