Skip to content

Commit da7300b

Browse files
authored
Merge pull request #2756 from signalwire/eslcoverity
[fs_cli, libesl] Coverity fixes.
2 parents 8831d8b + c3dff0f commit da7300b

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

libs/esl/fs_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ int main(int argc, char *argv[])
15211521

15221522
strncpy(internal_profile.host, "127.0.0.1", sizeof(internal_profile.host));
15231523
strncpy(internal_profile.pass, "ClueCon", sizeof(internal_profile.pass));
1524-
strncpy(internal_profile.name, hostname, sizeof(internal_profile.name));
1524+
snprintf(internal_profile.name, sizeof(internal_profile.name), "%s", hostname);
15251525
internal_profile.port = 8021;
15261526
set_fn_keys(&internal_profile);
15271527
esl_set_string(internal_profile.prompt_color, prompt_color);

libs/esl/src/cJSON.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,11 +1147,6 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
11471147
hooks->deallocate(buffer->buffer);
11481148
}
11491149

1150-
if (printed != NULL)
1151-
{
1152-
hooks->deallocate(printed);
1153-
}
1154-
11551150
return NULL;
11561151
}
11571152

libs/esl/src/esl.c

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,12 @@ ESL_DECLARE(int) esl_snprintf(char *buffer, size_t count, const char *fmt, ...)
284284

285285
static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...)
286286
{
287-
if (file && func && line && level && fmt) {
288-
return;
289-
}
287+
(void)file;
288+
(void)func;
289+
(void)line;
290+
(void)level;
291+
(void)fmt;
292+
290293
return;
291294
}
292295

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

698701

699-
esl_socket_reuseaddr(server_sock);
702+
if (esl_socket_reuseaddr(server_sock) != 0) {
703+
status = ESL_FAIL;
704+
goto end;
705+
}
700706

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

754-
esl_socket_reuseaddr(server_sock);
760+
if (esl_socket_reuseaddr(server_sock) != 0) {
761+
status = ESL_FAIL;
762+
goto end;
763+
}
755764

756765
memset(&addr, 0, sizeof(addr));
757766
addr.sin_family = AF_INET;
@@ -1060,7 +1069,10 @@ ESL_DECLARE(esl_status_t) esl_connect_timeout(esl_handle_t *handle, const char *
10601069
}
10611070
}
10621071
#else
1063-
fcntl(handle->sock, F_SETFL, fd_flags);
1072+
if (fcntl(handle->sock, F_SETFL, fd_flags)) {
1073+
snprintf(handle->err, sizeof(handle->err), "Socket Connection Error");
1074+
goto fail;
1075+
}
10641076
#endif
10651077
rval = 0;
10661078
}
@@ -1155,20 +1167,20 @@ ESL_DECLARE(esl_status_t) esl_disconnect(esl_handle_t *handle)
11551167
esl_event_safe_destroy(&handle->last_ievent);
11561168
esl_event_safe_destroy(&handle->info_event);
11571169

1158-
if (mutex) {
1159-
esl_mutex_unlock(mutex);
1160-
esl_mutex_lock(mutex);
1161-
esl_mutex_unlock(mutex);
1162-
esl_mutex_destroy(&mutex);
1163-
}
1164-
11651170
if (handle->packet_buf) {
11661171
esl_buffer_destroy(&handle->packet_buf);
11671172
}
11681173

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

1177+
if (mutex) {
1178+
esl_mutex_unlock(mutex);
1179+
esl_mutex_lock(mutex);
1180+
esl_mutex_unlock(mutex);
1181+
esl_mutex_destroy(&mutex);
1182+
}
1183+
11721184
return status;
11731185
}
11741186

@@ -1217,7 +1229,7 @@ ESL_DECLARE(esl_status_t) esl_recv_event_timed(esl_handle_t *handle, uint32_t ms
12171229
status = ESL_BREAK;
12181230
}
12191231

1220-
if (handle->mutex) esl_mutex_unlock(handle->mutex);
1232+
esl_mutex_unlock(handle->mutex);
12211233

12221234
return status;
12231235

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

1302-
if (hval) {
1303-
esl_url_decode(hval);
1304-
esl_log(ESL_LOG_DEBUG, "RECV HEADER [%s] = [%s]\n", hname, hval);
1305-
if (!strncmp(hval, "ARRAY::", 7)) {
1306-
esl_event_add_array(revent, hname, hval);
1307-
} else {
1308-
esl_event_add_header_string(revent, ESL_STACK_BOTTOM, hname, hval);
1309-
}
1314+
esl_url_decode(hval);
1315+
esl_log(ESL_LOG_DEBUG, "RECV HEADER [%s] = [%s]\n", hname, hval);
1316+
if (!strncmp(hval, "ARRAY::", 7)) {
1317+
esl_event_add_array(revent, hname, hval);
1318+
} else {
1319+
esl_event_add_header_string(revent, ESL_STACK_BOTTOM, hname, hval);
13101320
}
13111321

13121322
p = e;
@@ -1521,11 +1531,15 @@ ESL_DECLARE(esl_status_t) esl_send_recv_timed(esl_handle_t *handle, const char *
15211531
const char *hval;
15221532
esl_status_t status;
15231533

1524-
if (!handle || !handle->connected || handle->sock == ESL_SOCK_INVALID) {
1525-
return ESL_FAIL;
1526-
}
1534+
if (!handle) {
1535+
return ESL_FAIL;
1536+
}
15271537

15281538
esl_mutex_lock(handle->mutex);
1539+
if (!handle->connected || handle->sock == ESL_SOCK_INVALID) {
1540+
esl_mutex_unlock(handle->mutex);
1541+
return ESL_FAIL;
1542+
}
15291543

15301544
esl_event_safe_destroy(&handle->last_sr_event);
15311545

libs/esl/src/esl_event.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t st
545545
header->value = NULL;
546546
header->array = m;
547547
header->idx++;
548-
m = NULL;
549548
}
550549

551550
i = header->idx + 1;

0 commit comments

Comments
 (0)