Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fs_cli, libesl] Coverity fixes. #2756

Merged
merged 10 commits into from
Feb 4, 2025
2 changes: 1 addition & 1 deletion libs/esl/fs_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ int main(int argc, char *argv[])

strncpy(internal_profile.host, "127.0.0.1", sizeof(internal_profile.host));
strncpy(internal_profile.pass, "ClueCon", sizeof(internal_profile.pass));
strncpy(internal_profile.name, hostname, sizeof(internal_profile.name));
snprintf(internal_profile.name, sizeof(internal_profile.name), "%s", hostname);
internal_profile.port = 8021;
set_fn_keys(&internal_profile);
esl_set_string(internal_profile.prompt_color, prompt_color);
Expand Down
5 changes: 0 additions & 5 deletions libs/esl/src/cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,6 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
hooks->deallocate(buffer->buffer);
}

if (printed != NULL)
{
hooks->deallocate(printed);
}

return NULL;
}

Expand Down
64 changes: 39 additions & 25 deletions libs/esl/src/esl.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ ESL_DECLARE(int) esl_snprintf(char *buffer, size_t count, const char *fmt, ...)

static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...)
{
if (file && func && line && level && fmt) {
return;
}
(void)file;
(void)func;
(void)line;
(void)level;
(void)fmt;

return;
}

Expand Down Expand Up @@ -696,7 +699,10 @@ ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_list
}


esl_socket_reuseaddr(server_sock);
if (esl_socket_reuseaddr(server_sock) != 0) {
status = ESL_FAIL;
goto end;
}

memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
Expand Down Expand Up @@ -751,7 +757,10 @@ ESL_DECLARE(esl_status_t) esl_listen_threaded(const char *host, esl_port_t port,
return ESL_FAIL;
}

esl_socket_reuseaddr(server_sock);
if (esl_socket_reuseaddr(server_sock) != 0) {
status = ESL_FAIL;
goto end;
}

memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
Expand Down Expand Up @@ -1060,7 +1069,10 @@ ESL_DECLARE(esl_status_t) esl_connect_timeout(esl_handle_t *handle, const char *
}
}
#else
fcntl(handle->sock, F_SETFL, fd_flags);
if (fcntl(handle->sock, F_SETFL, fd_flags)) {
snprintf(handle->err, sizeof(handle->err), "Socket Connection Error");
goto fail;
}
#endif
rval = 0;
}
Expand Down Expand Up @@ -1155,20 +1167,20 @@ ESL_DECLARE(esl_status_t) esl_disconnect(esl_handle_t *handle)
esl_event_safe_destroy(&handle->last_ievent);
esl_event_safe_destroy(&handle->info_event);

if (mutex) {
esl_mutex_unlock(mutex);
esl_mutex_lock(mutex);
esl_mutex_unlock(mutex);
esl_mutex_destroy(&mutex);
}

if (handle->packet_buf) {
esl_buffer_destroy(&handle->packet_buf);
}

memset(handle, 0, sizeof(*handle));
handle->destroyed = 1;

if (mutex) {
esl_mutex_unlock(mutex);
esl_mutex_lock(mutex);
esl_mutex_unlock(mutex);
esl_mutex_destroy(&mutex);
}

return status;
}

Expand Down Expand Up @@ -1217,7 +1229,7 @@ ESL_DECLARE(esl_status_t) esl_recv_event_timed(esl_handle_t *handle, uint32_t ms
status = ESL_BREAK;
}

if (handle->mutex) esl_mutex_unlock(handle->mutex);
esl_mutex_unlock(handle->mutex);

return status;

Expand Down Expand Up @@ -1299,14 +1311,12 @@ ESL_DECLARE(esl_status_t) esl_recv_event(esl_handle_t *handle, int check_q, esl_
*e++ = '\0';
while(*e == '\n' || *e == '\r') e++;

if (hval) {
esl_url_decode(hval);
esl_log(ESL_LOG_DEBUG, "RECV HEADER [%s] = [%s]\n", hname, hval);
if (!strncmp(hval, "ARRAY::", 7)) {
esl_event_add_array(revent, hname, hval);
} else {
esl_event_add_header_string(revent, ESL_STACK_BOTTOM, hname, hval);
}
esl_url_decode(hval);
esl_log(ESL_LOG_DEBUG, "RECV HEADER [%s] = [%s]\n", hname, hval);
if (!strncmp(hval, "ARRAY::", 7)) {
esl_event_add_array(revent, hname, hval);
} else {
esl_event_add_header_string(revent, ESL_STACK_BOTTOM, hname, hval);
}

p = e;
Expand Down Expand Up @@ -1521,11 +1531,15 @@ ESL_DECLARE(esl_status_t) esl_send_recv_timed(esl_handle_t *handle, const char *
const char *hval;
esl_status_t status;

if (!handle || !handle->connected || handle->sock == ESL_SOCK_INVALID) {
return ESL_FAIL;
}
if (!handle) {
return ESL_FAIL;
}

esl_mutex_lock(handle->mutex);
if (!handle->connected || handle->sock == ESL_SOCK_INVALID) {
esl_mutex_unlock(handle->mutex);
return ESL_FAIL;
}

esl_event_safe_destroy(&handle->last_sr_event);

Expand Down
1 change: 0 additions & 1 deletion libs/esl/src/esl_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t st
header->value = NULL;
header->array = m;
header->idx++;
m = NULL;
}

i = header->idx + 1;
Expand Down