Skip to content

Commit

Permalink
fixup: various fixes for coverity warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kgiusti committed Aug 29, 2024
1 parent 9a77d54 commit 8037cdb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/tls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand All @@ -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

Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand Down
39 changes: 23 additions & 16 deletions src/tls/tls_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

//
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8037cdb

Please sign in to comment.