> Date: 2026-09-30 12:45:46+0800
> From: "Kevin J. McCarthy" <[email protected]>
>
> Now that the fields are type char *, they will be NULL if they contain
> an "empty" value.  Add checks to make sure prompts and debug
> statements don't segv.
> 
> Change checks for empty character arrays from !var[0] to !var.

Reviewed-by: Alejandro Colomar <[email protected]>


Cheers,
Alex

> ---
>  account.c         | 10 +++++-----
>  imap/auth_gss.c   |  4 ++--
>  imap/auth_login.c |  6 +++---
>  imap/browse.c     |  4 ++--
>  imap/command.c    |  6 +++---
>  imap/imap.c       |  2 +-
>  mutt_sasl_gnu.c   |  8 ++++----
>  mutt_socket.c     | 18 +++++++++---------
>  mutt_ssl.c        |  6 +++---
>  mutt_tunnel.c     |  6 +++---
>  pop_auth.c        | 12 ++++++------
>  pop_lib.c         |  2 +-
>  12 files changed, 42 insertions(+), 42 deletions(-)
> 
> diff --git a/account.c b/account.c
> index dcb59b36..5a711547 100644
> --- a/account.c
> +++ b/account.c
> @@ -213,7 +213,7 @@ int mutt_account_getuser(ACCOUNT *account)
>    /* prompt (defaults to unix username), copy into account->user */
>    else
>    {
> -    snprintf(prompt, sizeof(prompt), _("Username at %s: "), account->host);
> +    snprintf(prompt, sizeof(prompt), _("Username at %s: "), 
> NONULL(account->host));
>      strfcpy(userbuf, NONULL(Username), sizeof(userbuf));
>      if (mutt_get_field_unbuffered(prompt, userbuf, sizeof(userbuf), 0))
>        return -1;
> @@ -259,8 +259,8 @@ static void getpass_prompt(char *prompt, size_t 
> prompt_size, ACCOUNT *account)
>       %s@%s is user@host
>    */
>    snprintf(prompt, prompt_size, _("Password for %s@%s: "),
> -           account->flags & MUTT_ACCT_LOGIN ? account->login : account->user,
> -           account->host);
> +           account->flags & MUTT_ACCT_LOGIN ? NONULL(account->login) : 
> NONULL(account->user),
> +           NONULL(account->host));
>  }
>  
>  int _mutt_account_getpass(ACCOUNT *account,
> @@ -385,11 +385,11 @@ int mutt_account_getoauthbearer(ACCOUNT *account, 
> BUFFER *authbearer, int xoauth
>    if (xoauth2)
>      mutt_buffer_printf(unencoded_bearertoken,
>                         "user=%s\001auth=Bearer %s\001\001",
> -                       account->login, token);
> +                       NONULL(account->login), token);
>    else
>      mutt_buffer_printf(unencoded_bearertoken,
>                         "n,a=%s,\001host=%s\001port=%d\001auth=Bearer 
> %s\001\001",
> -                       account->login, account->host, account->port, token);
> +                       NONULL(account->login), NONULL(account->host), 
> account->port, token);
>  
>    FREE(&token);
>  
> diff --git a/imap/auth_gss.c b/imap/auth_gss.c
> index dac83cc2..feb0f184 100644
> --- a/imap/auth_gss.c
> +++ b/imap/auth_gss.c
> @@ -121,7 +121,7 @@ imap_auth_res_t imap_auth_gss(IMAP_DATA *idata, const 
> char *method)
>    buf2 = mutt_buffer_pool_get();
>  
>    /* get an IMAP service ticket for the server */
> -  mutt_buffer_printf(buf1, "imap@%s", idata->conn->account.host);
> +  mutt_buffer_printf(buf1, "imap@%s", NONULL(idata->conn->account.host));
>    request_buf.value = buf1->data;
>    request_buf.length = mutt_buffer_len(buf1);
>    maj_stat = gss_import_name(&min_stat, &request_buf, gss_nt_service_name,
> @@ -305,7 +305,7 @@ imap_auth_res_t imap_auth_gss(IMAP_DATA *idata, const 
> char *method)
>  
>    mutt_buffer_to_base64(buf1, send_token.value, send_token.length);
>    muttdbg(2, "Requesting authorisation as %s",
> -          idata->conn->account.user);
> +          NONULL(idata->conn->account.user));
>    mutt_buffer_addstr(buf1, "\r\n");
>    mutt_socket_write(idata->conn, mutt_b2s(buf1));
>  
> diff --git a/imap/auth_login.c b/imap/auth_login.c
> index bad6fa39..1236122f 100644
> --- a/imap/auth_login.c
> +++ b/imap/auth_login.c
> @@ -46,8 +46,8 @@ imap_auth_res_t imap_auth_login(IMAP_DATA *idata, const 
> char *method)
>  
>    mutt_message _("Logging in...");
>  
> -  imap_quote_string(q_user, sizeof(q_user), idata->conn->account.user);
> -  imap_quote_string(q_pass, sizeof(q_pass), idata->conn->account.pass);
> +  imap_quote_string(q_user, sizeof(q_user), 
> NONULL(idata->conn->account.user));
> +  imap_quote_string(q_pass, sizeof(q_pass), 
> NONULL(idata->conn->account.pass));
>  
>  #ifdef DEBUG
>    /* don't print the password unless we're at the ungodly debugging level
> @@ -56,7 +56,7 @@ imap_auth_res_t imap_auth_login(IMAP_DATA *idata, const 
> char *method)
>     * additional protection */
>  
>    if (debuglevel < IMAP_LOG_PASS)
> -    muttdbg(2, "Sending LOGIN command for %s...", idata->conn->account.user);
> +    muttdbg(2, "Sending LOGIN command for %s...", 
> NONULL(idata->conn->account.user));
>  #endif
>  
>    snprintf(buf, sizeof(buf), "LOGIN %s %s", q_user, q_pass);
> diff --git a/imap/browse.c b/imap/browse.c
> index 22e5c4df..9423141d 100644
> --- a/imap/browse.c
> +++ b/imap/browse.c
> @@ -244,7 +244,7 @@ int imap_mailbox_create(const char *folder, BUFFER 
> *result)
>  
>    if (!(idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW)))
>    {
> -    muttdbg(1, "imap_mailbox_create: Couldn't find open connection to %s", 
> mx.account.host);
> +    muttdbg(1, "imap_mailbox_create: Couldn't find open connection to %s", 
> NONULL(mx.account.host));
>      goto fail;
>    }
>  
> @@ -299,7 +299,7 @@ int imap_mailbox_rename(const char *mailbox, BUFFER 
> *result)
>  
>    if (!(idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW)))
>    {
> -    muttdbg(1, "imap_mailbox_rename: Couldn't find open connection to %s", 
> mx.account.host);
> +    muttdbg(1, "imap_mailbox_rename: Couldn't find open connection to %s", 
> NONULL(mx.account.host));
>      goto fail;
>    }
>  
> diff --git a/imap/command.c b/imap/command.c
> index 15839a3f..cce25776 100644
> --- a/imap/command.c
> +++ b/imap/command.c
> @@ -264,7 +264,7 @@ int imap_exec(IMAP_DATA *idata, const char *cmdstr, int 
> flags)
>        (ImapPollTimeout > 0) &&
>        (mutt_socket_poll(idata->conn, ImapPollTimeout)) == 0)
>    {
> -    mutt_error(_("Connection to %s timed out"), idata->conn->account.host);
> +    mutt_error(_("Connection to %s timed out"), 
> NONULL(idata->conn->account.host));
>      mutt_sleep(0);
>      cmd_handle_fatal(idata);
>      return -1;
> @@ -345,7 +345,7 @@ int imap_cmd_idle(IMAP_DATA *idata)
>    if ((ImapPollTimeout > 0) &&
>        (mutt_socket_poll(idata->conn, ImapPollTimeout)) == 0)
>    {
> -    mutt_error(_("Connection to %s timed out"), idata->conn->account.host);
> +    mutt_error(_("Connection to %s timed out"), 
> NONULL(idata->conn->account.host));
>      mutt_sleep(0);
>      cmd_handle_fatal(idata);
>      return -1;
> @@ -500,7 +500,7 @@ static void cmd_handle_fatal(IMAP_DATA *idata)
>      mx_fastclose_mailbox(idata->ctx);
>      mutt_socket_close(idata->conn);
>      mutt_error(_("Mailbox %s@%s closed"),
> -               idata->conn->account.login, idata->conn->account.host);
> +               NONULL(idata->conn->account.login), 
> NONULL(idata->conn->account.host));
>      mutt_sleep(1);
>      idata->state = IMAP_DISCONNECTED;
>    }
> diff --git a/imap/imap.c b/imap/imap.c
> index 20b80dfc..b8bb048a 100644
> --- a/imap/imap.c
> +++ b/imap/imap.c
> @@ -195,7 +195,7 @@ void imap_logout_all(void)
>  
>      if (conn->account.type == MUTT_ACCT_TYPE_IMAP && conn->fd >= 0)
>      {
> -      mutt_message(_("Closing connection to %s..."), conn->account.host);
> +      mutt_message(_("Closing connection to %s..."), 
> NONULL(conn->account.host));
>        imap_logout((IMAP_DATA**) (void*) &conn->data);
>        mutt_clear_error();
>        mutt_socket_free(conn);
> diff --git a/mutt_sasl_gnu.c b/mutt_sasl_gnu.c
> index 2bd5afbf..65d0237d 100644
> --- a/mutt_sasl_gnu.c
> +++ b/mutt_sasl_gnu.c
> @@ -172,7 +172,7 @@ static int mutt_gsasl_callback(Gsasl *ctx, Gsasl_session 
> *sctx,
>      case GSASL_PASSWORD:
>        if (mutt_account_getpass(&conn->account))
>          return rc;
> -      gsasl_property_set(sctx, GSASL_PASSWORD, conn->account.pass);
> +      gsasl_property_set(sctx, GSASL_PASSWORD, NONULL(conn->account.pass));
>        rc = GSASL_OK;
>        break;
>  
> @@ -180,7 +180,7 @@ static int mutt_gsasl_callback(Gsasl *ctx, Gsasl_session 
> *sctx,
>        /* whom the provided password belongs to: login */
>        if (mutt_account_getlogin(&conn->account))
>          return rc;
> -      gsasl_property_set(sctx, GSASL_AUTHID, conn->account.login);
> +      gsasl_property_set(sctx, GSASL_AUTHID, NONULL(conn->account.login));
>        rc = GSASL_OK;
>        break;
>  
> @@ -188,7 +188,7 @@ static int mutt_gsasl_callback(Gsasl *ctx, Gsasl_session 
> *sctx,
>        /* name of the user whose mail/resources you intend to access: user */
>        if (mutt_account_getuser(&conn->account))
>          return rc;
> -      gsasl_property_set(sctx, GSASL_AUTHZID, conn->account.user);
> +      gsasl_property_set(sctx, GSASL_AUTHZID, NONULL(conn->account.user));
>        rc = GSASL_OK;
>        break;
>  
> @@ -217,7 +217,7 @@ static int mutt_gsasl_callback(Gsasl *ctx, Gsasl_session 
> *sctx,
>        break;
>  
>      case GSASL_HOSTNAME:
> -      gsasl_property_set(sctx, GSASL_HOSTNAME, conn->account.host);
> +      gsasl_property_set(sctx, GSASL_HOSTNAME, NONULL(conn->account.host));
>        rc = GSASL_OK;
>        break;
>  
> diff --git a/mutt_socket.c b/mutt_socket.c
> index 5065bbdd..1a4ca46d 100644
> --- a/mutt_socket.c
> +++ b/mutt_socket.c
> @@ -184,7 +184,7 @@ int mutt_socket_readchar(CONNECTION *conn, char *c)
>      conn->bufpos = 0;
>      if (conn->available == 0)
>      {
> -      mutt_error(_("Connection to %s closed"), conn->account.host);
> +      mutt_error(_("Connection to %s closed"), NONULL(conn->account.host));
>        mutt_sleep(2);
>      }
>      if (conn->available <= 0)
> @@ -489,7 +489,7 @@ int raw_socket_read(CONNECTION *conn, char *buf, size_t 
> len)
>  
>    if (rc < 0)
>    {
> -    mutt_error(_("Error talking to %s (%s)"), conn->account.host,
> +    mutt_error(_("Error talking to %s (%s)"), NONULL(conn->account.host),
>                 strerror(errno));
>      mutt_sleep(2);
>      return -1;
> @@ -512,7 +512,7 @@ int raw_socket_write(CONNECTION *conn, const char *buf, 
> size_t count)
>  
>      if (rc < 0)
>      {
> -      mutt_error(_("Error talking to %s (%s)"), conn->account.host,
> +      mutt_error(_("Error talking to %s (%s)"), NONULL(conn->account.host),
>                   strerror(errno));
>        mutt_sleep(2);
>        return -1;
> @@ -594,9 +594,9 @@ int raw_socket_open(CONNECTION *conn)
>    snprintf(port, sizeof(port), "%d", conn->account.port);
>  
>  # if defined(HAVE_LIBIDN) || defined(HAVE_LIBIDN2)
> -  if (idna_to_ascii_lz(conn->account.host, &host_idna, 1) != IDNA_SUCCESS)
> +  if (idna_to_ascii_lz(NONULL(conn->account.host), &host_idna, 1) != 
> IDNA_SUCCESS)
>    {
> -    mutt_error(_("Bad IDN \"%s\"."), conn->account.host);
> +    mutt_error(_("Bad IDN \"%s\"."), NONULL(conn->account.host));
>      return -1;
>    }
>  # else
> @@ -604,7 +604,7 @@ int raw_socket_open(CONNECTION *conn)
>  # endif
>  
>    if (!option(OPTNOCURSES))
> -    mutt_message(_("Looking up %s..."), conn->account.host);
> +    mutt_message(_("Looking up %s..."), NONULL(conn->account.host));
>  
>    rc = getaddrinfo(host_idna, port, &hints, &res);
>  
> @@ -614,13 +614,13 @@ int raw_socket_open(CONNECTION *conn)
>  
>    if (rc)
>    {
> -    mutt_error(_("Could not find the host \"%s\""), conn->account.host);
> +    mutt_error(_("Could not find the host \"%s\""), 
> NONULL(conn->account.host));
>      mutt_sleep(2);
>      return -1;
>    }
>  
>    if (!option(OPTNOCURSES))
> -    mutt_message(_("Connecting to %s..."), conn->account.host);
> +    mutt_message(_("Connecting to %s..."), NONULL(conn->account.host));
>  
>    rc = -1;
>    for (cur = res; cur != NULL; cur = cur->ai_next)
> @@ -703,7 +703,7 @@ int raw_socket_open(CONNECTION *conn)
>  #endif
>    if (rc)
>    {
> -    mutt_error(_("Could not connect to %s (%s)."), conn->account.host,
> +    mutt_error(_("Could not connect to %s (%s)."), 
> NONULL(conn->account.host),
>                 (rc > 0) ? strerror(rc) : _("unknown error"));
>      mutt_sleep(2);
>      return -1;
> diff --git a/mutt_ssl.c b/mutt_ssl.c
> index e4c973cf..9a390343 100644
> --- a/mutt_ssl.c
> +++ b/mutt_ssl.c
> @@ -554,7 +554,7 @@ static int ssl_negotiate(CONNECTION *conn, sslsockdata 
> *ssldata)
>    const char *errmsg;
>    char *hostname;
>  
> -  hostname = SslVerifyHostOverride ? SslVerifyHostOverride : 
> conn->account.host;
> +  hostname = SslVerifyHostOverride ? SslVerifyHostOverride : 
> NONULL(conn->account.host);
>  
>    if (HostExDataIndex == -1)
>    {
> @@ -1415,7 +1415,7 @@ static void client_cert_prompt(char *prompt, size_t 
> prompt_size, ACCOUNT *accoun
>       to decrypt the cert.  %s is the hostname.
>    */
>    snprintf(prompt, prompt_size, _("Password for %s client cert: "),
> -           account->host);
> +           NONULL(account->host));
>  }
>  
>  static int ssl_passwd_cb(char *buf, int size, int rwflag, void *userdata)
> @@ -1430,5 +1430,5 @@ static int ssl_passwd_cb(char *buf, int size, int 
> rwflag, void *userdata)
>    if (_mutt_account_getpass(account, client_cert_prompt))
>      return 0;
>  
> -  return snprintf(buf, size, "%s", account->pass);
> +  return snprintf(buf, size, "%s", NONULL(account->pass));
>  }
> diff --git a/mutt_tunnel.c b/mutt_tunnel.c
> index cd2f365b..004a9255 100644
> --- a/mutt_tunnel.c
> +++ b/mutt_tunnel.c
> @@ -152,7 +152,7 @@ static int tunnel_socket_close(CONNECTION *conn)
>    waitpid(tunnel->pid, &status, 0);
>    if (!WIFEXITED(status) || WEXITSTATUS(status))
>    {
> -    mutt_error(_("Tunnel to %s returned error %d (%s)"), conn->account.host,
> +    mutt_error(_("Tunnel to %s returned error %d (%s)"), 
> NONULL(conn->account.host),
>                 WEXITSTATUS(status),
>                 NONULL(mutt_strsysexit(WEXITSTATUS(status))));
>      mutt_sleep(2);
> @@ -174,7 +174,7 @@ static int tunnel_socket_read(CONNECTION *conn, char 
> *buf, size_t len)
>  
>    if (rc < 0)
>    {
> -    mutt_error(_("Tunnel error talking to %s: %s"), conn->account.host,
> +    mutt_error(_("Tunnel error talking to %s: %s"), 
> NONULL(conn->account.host),
>                 strerror(errno));
>      mutt_sleep(1);
>      return -1;
> @@ -198,7 +198,7 @@ static int tunnel_socket_write(CONNECTION *conn, const 
> char *buf, size_t len)
>  
>      if (rc < 0)
>      {
> -      mutt_error(_("Tunnel error talking to %s: %s"), conn->account.host,
> +      mutt_error(_("Tunnel error talking to %s: %s"), 
> NONULL(conn->account.host),
>                   strerror(errno));
>        mutt_sleep(1);
>        return -1;
> diff --git a/pop_auth.c b/pop_auth.c
> index e3072fbd..28539582 100644
> --- a/pop_auth.c
> +++ b/pop_auth.c
> @@ -333,7 +333,7 @@ static pop_auth_res_t pop_auth_apop(POP_DATA *pop_data, 
> const char *method)
>    size_t i;
>  
>    if (mutt_account_getpass(&pop_data->conn->account) ||
> -      !pop_data->conn->account.pass[0])
> +      !pop_data->conn->account.pass)
>      return POP_A_FAILURE;
>  
>    if (!pop_data->timestamp)
> @@ -351,7 +351,7 @@ static pop_auth_res_t pop_auth_apop(POP_DATA *pop_data, 
> const char *method)
>    /* Compute the authentication hash to send to the server */
>    md5_init_ctx(&ctx);
>    md5_process_bytes(pop_data->timestamp, strlen(pop_data->timestamp), &ctx);
> -  md5_process_bytes(pop_data->conn->account.pass,
> +  md5_process_bytes(NONULL(pop_data->conn->account.pass),
>                      mutt_strlen(pop_data->conn->account.pass), &ctx);
>    md5_finish_ctx(&ctx, digest);
>  
> @@ -359,7 +359,7 @@ static pop_auth_res_t pop_auth_apop(POP_DATA *pop_data, 
> const char *method)
>      sprintf(hash + 2 * i, "%02x", digest[i]);
>  
>    /* Send APOP command to server */
> -  snprintf(buf, sizeof(buf), "APOP %s %s\r\n", pop_data->conn->account.user, 
> hash);
> +  snprintf(buf, sizeof(buf), "APOP %s %s\r\n", 
> NONULL(pop_data->conn->account.user), hash);
>  
>    switch (pop_query(pop_data, buf, sizeof(buf)))
>    {
> @@ -385,12 +385,12 @@ static pop_auth_res_t pop_auth_user(POP_DATA *pop_data, 
> const char *method)
>      return POP_A_UNAVAIL;
>  
>    if (mutt_account_getpass(&pop_data->conn->account) ||
> -      !pop_data->conn->account.pass[0])
> +      !pop_data->conn->account.pass)
>      return POP_A_FAILURE;
>  
>    mutt_message _("Logging in...");
>  
> -  snprintf(buf, sizeof(buf), "USER %s\r\n", pop_data->conn->account.user);
> +  snprintf(buf, sizeof(buf), "USER %s\r\n", 
> NONULL(pop_data->conn->account.user));
>    ret = pop_query(pop_data, buf, sizeof(buf));
>  
>    if (pop_data->cmd_user == 2)
> @@ -558,7 +558,7 @@ int pop_authenticate(POP_DATA *pop_data)
>    int attempts = 0;
>    int ret = POP_A_UNAVAIL;
>  
> -  if (mutt_account_getuser(acct) || !acct->user[0])
> +  if (mutt_account_getuser(acct) || !acct->user)
>      return -3;
>  
>    if (PopAuthenticators)
> diff --git a/pop_lib.c b/pop_lib.c
> index 0e4311b0..ea1ccbd7 100644
> --- a/pop_lib.c
> +++ b/pop_lib.c
> @@ -236,7 +236,7 @@ int pop_connect(POP_DATA *pop_data)
>    if (mutt_socket_open(pop_data->conn) < 0 ||
>        mutt_socket_readln(buf, sizeof(buf), pop_data->conn) < 0)
>    {
> -    mutt_error(_("Error connecting to server: %s"), 
> pop_data->conn->account.host);
> +    mutt_error(_("Error connecting to server: %s"), 
> NONULL(pop_data->conn->account.host));
>      return -1;
>    }
>  
> -- 
> 2.55.0
> 

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to