From 8037cdb17017399ffde4435f87543896fca0c2dd Mon Sep 17 00:00:00 2001 From: Kenneth Giusti Date: Thu, 29 Aug 2024 13:44:19 -0400 Subject: [PATCH] fixup: various fixes for coverity warnings --- src/tls/tls.c | 7 +++++-- src/tls/tls_raw.c | 39 +++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/tls/tls.c b/src/tls/tls.c index 972ebb757..42790689f 100644 --- a/src/tls/tls.c +++ b/src/tls/tls.c @@ -107,6 +107,7 @@ QD_EXPORT void *qd_tls_configure_ssl_profile(qd_dispatch_t *qd, qd_entity_t *ent if (!name || qd_error_code()) { free(name); qd_log(LOG_AGENT, QD_LOG_ERROR, "Unable to create sslProfile: %s", qd_error_message()); + return 0; } qd_tls_context_t *tls_context = new_qd_tls_context_t(); @@ -287,7 +288,7 @@ qd_tls_session_t *qd_tls_session_raw(qd_tls_config_t *tls_config, const char *pe const char **alpn_protocols, size_t alpn_protocol_count, void *context, qd_tls_session_on_secure_cb_t *on_secure) { - assert(tls_config->p_type == QD_TLS_TYPE_PROTON_RAW && tls_config->pn_raw); + assert(tls_config->p_type == QD_TLS_TYPE_PROTON_RAW); qd_error_clear(); @@ -305,6 +306,7 @@ qd_tls_session_t *qd_tls_session_raw(qd_tls_config_t *tls_config, const char *pe // safe. sys_mutex_lock(&tls_config->lock); + assert(tls_config->pn_raw); tls_session->uid_format = CHECKED_STRDUP(tls_config->uid_format); // may be changed by mgmt thread tls_session->version = tls_config->version; // may be changed by mgmt thread @@ -370,7 +372,7 @@ qd_tls_session_t *qd_tls_session_raw(qd_tls_config_t *tls_config, const char *pe qd_tls_session_t *qd_tls_session_amqp(qd_tls_config_t *tls_config, pn_transport_t *tport, bool allow_unencrypted) { - assert(tls_config->p_type == QD_TLS_TYPE_PROTON_AMQP && tls_config->pn_amqp); + assert(tls_config->p_type == QD_TLS_TYPE_PROTON_AMQP); qd_error_clear(); @@ -391,6 +393,7 @@ qd_tls_session_t *qd_tls_session_amqp(qd_tls_config_t *tls_config, pn_transport_ goto error; } + assert(tls_config->pn_amqp); int rc = pn_ssl_init(tls_session->pn_amqp, tls_config->pn_amqp, 0); if (rc) { sys_mutex_unlock(&tls_config->lock); diff --git a/src/tls/tls_raw.c b/src/tls/tls_raw.c index 07a7a6c6e..f0e3cf064 100644 --- a/src/tls/tls_raw.c +++ b/src/tls/tls_raw.c @@ -190,24 +190,30 @@ int qd_tls_session_do_io(qd_tls_session_t *session, // capacity = pn_tls_get_encrypt_output_buffer_capacity(session->pn_raw); - if (debug && capacity) { - qd_log_impl(log_module, QD_LOG_DEBUG, __FILE__, __LINE__, "[C%" PRIu64 "] giving %zu encrypt output buffers", conn_id, capacity); - } - while (capacity-- > 0) { - _pn_buf_desc_give_buffer(&pn_buf_desc, qd_buffer()); - given = pn_tls_give_encrypt_output_buffers(session->pn_raw, &pn_buf_desc, 1); - (void) given; - assert(given == 1); + if (capacity > 0) { + if (debug) { + qd_log_impl(log_module, QD_LOG_DEBUG, __FILE__, __LINE__, "[C%" PRIu64 "] giving %zu encrypt output buffers", conn_id, capacity); + } + while (capacity > 0) { + _pn_buf_desc_give_buffer(&pn_buf_desc, qd_buffer()); + given = pn_tls_give_encrypt_output_buffers(session->pn_raw, &pn_buf_desc, 1); + (void) given; + assert(given == 1); + capacity -= 1; + } } capacity = pn_tls_get_decrypt_output_buffer_capacity(session->pn_raw); - if (debug && capacity) { - qd_log_impl(log_module, QD_LOG_DEBUG, __FILE__, __LINE__, "[C%" PRIu64 "] giving %zu decrypt output buffers", conn_id, capacity); - } - while (capacity-- > 0) { - _pn_buf_desc_give_buffer(&pn_buf_desc, qd_buffer()); - given = pn_tls_give_decrypt_output_buffers(session->pn_raw, &pn_buf_desc, 1); - (void) given; - assert(given == 1); + if (capacity > 0) { + if (debug) { + qd_log_impl(log_module, QD_LOG_DEBUG, __FILE__, __LINE__, "[C%" PRIu64 "] giving %zu decrypt output buffers", conn_id, capacity); + } + while (capacity > 0) { + _pn_buf_desc_give_buffer(&pn_buf_desc, qd_buffer()); + given = pn_tls_give_decrypt_output_buffers(session->pn_raw, &pn_buf_desc, 1); + (void) given; + assert(given == 1); + capacity -= 1; + } } // @@ -375,6 +381,7 @@ int qd_tls_session_do_io(qd_tls_session_t *session, // if (input_data) { + assert(input_data_count); total_octets = 0; taken = 0; while (pn_tls_take_decrypt_output_buffers(session->pn_raw, &pn_buf_desc, 1) == 1) {