[core] Coverity fixes
* [core] Coverity CID 1024233 (Dereference before null check) * [core] Coverity CID 1024239 (Dereference before null check) * [core] Coverity CID 1024242 (Dereference before null check) * [core] Coverity CID 1024243 (Dereference before null check) * [core] Coverity CID 1024453 (Dereference before null check) * [core] Coverity CID 1024554 (Logically dead code) * [core] Coverity CID 1024868 (unchecked return value from library) * [core] Coverity CID 1024869 (unchecked return value from library) * [core] Coverity CID 1468281 (Dereference before null check) * [core] Coverity CID 1024238 (Dereference before null check) * [core] Coverity CID 1468621 (Copy into fixed size buffer) * [core] Coverity CID 1024871 (Unchecked return value)
This commit is contained in:
parent
e764f292b5
commit
55f2dc4759
|
@ -120,8 +120,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c
|
|||
}
|
||||
} else { /* replace real_read_codec */
|
||||
switch_codec_t *cur_codec;
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec replaced with %s:%d\n",
|
||||
switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode);
|
||||
switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1);
|
||||
/* Set real_read_codec to front of the list of read_codecs */
|
||||
cur_codec = session->read_codec;
|
||||
while (cur_codec != NULL) {
|
||||
|
@ -129,8 +130,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c
|
|||
cur_codec->next = codec;
|
||||
break;
|
||||
}
|
||||
|
||||
cur_codec = cur_codec->next;
|
||||
}
|
||||
|
||||
session->real_read_codec = codec;
|
||||
session->real_read_impl = *codec->implementation;
|
||||
|
||||
|
@ -154,6 +157,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c
|
|||
session->bug_codec.implementation->iananame, session->bug_codec.implementation->ianacode);
|
||||
switch_core_codec_destroy(&session->bug_codec);
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(session->bug_rwlock);
|
||||
} else {
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
|
@ -169,6 +173,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c
|
|||
if (session->read_impl.actual_samples_per_second != session->read_impl.samples_per_second) {
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
|
||||
}
|
||||
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
|
@ -191,6 +196,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c
|
|||
}
|
||||
|
||||
switch_mutex_unlock(session->codec_read_mutex);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -221,7 +227,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
|
|||
goto end;
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Push codec %s:%d\n",
|
||||
switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode);
|
||||
switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1);
|
||||
codec->next = session->read_codec;
|
||||
session->read_codec = codec;
|
||||
if (codec->implementation) {
|
||||
|
|
|
@ -2071,15 +2071,18 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit
|
|||
switch_mutex_lock(CUSTOM_HASH_MUTEX);
|
||||
|
||||
if (!(subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
|
||||
switch_event_reserve_subclass_detailed(id, subclass_name);
|
||||
subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name);
|
||||
subclass->bind = 1;
|
||||
if (switch_event_reserve_subclass_detailed(id, subclass_name) == SWITCH_STATUS_SUCCESS) {
|
||||
if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
|
||||
subclass->bind = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch_mutex_unlock(CUSTOM_HASH_MUTEX);
|
||||
|
||||
if (!subclass) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not reserve subclass. '%s'\n", subclass_name);
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -2094,6 +2097,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit
|
|||
if (subclass_name) {
|
||||
event_node->subclass_name = DUP(subclass_name);
|
||||
}
|
||||
|
||||
event_node->callback = callback;
|
||||
event_node->user_data = user_data;
|
||||
|
||||
|
@ -2952,14 +2956,17 @@ static void ecd_deliver(event_channel_data_t **ecdP)
|
|||
int x_argc = switch_separate_string_string(key, (char*) sep, x_argv, SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS);
|
||||
char buf[1024];
|
||||
int i, r;
|
||||
|
||||
for(i=x_argc - 1; i > 0; i--) {
|
||||
int z;
|
||||
|
||||
memset(buf, 0, 1024);
|
||||
sprintf(buf, "%s", x_argv[0]);
|
||||
switch_snprintf(buf, sizeof(buf), "%s", x_argv[0]);
|
||||
for(z=1; z < i; z++) {
|
||||
strcat(buf, sep);
|
||||
strcat(buf, x_argv[z]);
|
||||
strncat(buf, x_argv[z], sizeof(buf) - strlen(buf) - 1);
|
||||
}
|
||||
|
||||
r = _switch_event_channel_broadcast(buf, ecd->event_channel, ecd->json, ecd->key, ecd->id);
|
||||
t += r;
|
||||
if (r && switch_core_test_flag(SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE)) {
|
||||
|
@ -2968,11 +2975,13 @@ static void ecd_deliver(event_channel_data_t **ecdP)
|
|||
}
|
||||
} else {
|
||||
char *p = NULL;
|
||||
|
||||
if ((p = strchr(key, '.'))) {
|
||||
*p = '\0';
|
||||
t += _switch_event_channel_broadcast(key, ecd->event_channel, ecd->json, ecd->key, ecd->id);
|
||||
}
|
||||
}
|
||||
|
||||
switch_safe_free(key);
|
||||
|
||||
t += _switch_event_channel_broadcast(SWITCH_EVENT_CHANNEL_GLOBAL, ecd->event_channel, ecd->json, ecd->key, ecd->id);
|
||||
|
@ -2980,6 +2989,7 @@ static void ecd_deliver(event_channel_data_t **ecdP)
|
|||
if(t == 0) {
|
||||
if (switch_core_test_flag(SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON)) {
|
||||
char *json = cJSON_Print(ecd->json);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no subscribers for %s , %s => %s\n", ecd->event_channel, ecd->key, json);
|
||||
switch_safe_free(json);
|
||||
} else {
|
||||
|
|
|
@ -186,15 +186,16 @@ struct key_collect {
|
|||
static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void *obj)
|
||||
{
|
||||
struct key_collect *collect = (struct key_collect *) obj;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(collect->session);
|
||||
switch_channel_t *channel = NULL;
|
||||
char buf[10] = SWITCH_BLANK_STRING;
|
||||
switch_application_interface_t *application_interface = NULL;
|
||||
|
||||
if (collect->session) {
|
||||
if (switch_core_session_read_lock(collect->session) != SWITCH_STATUS_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (!collect->session) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
channel = switch_core_session_get_channel(collect->session);
|
||||
if (switch_core_session_read_lock(collect->session) != SWITCH_STATUS_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -232,6 +233,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void
|
|||
switch_channel_set_flag(channel, CF_WINNER);
|
||||
switch_channel_set_variable(channel, "group_dial_status", "winner");
|
||||
}
|
||||
|
||||
goto wbreak;
|
||||
}
|
||||
|
||||
|
@ -271,6 +273,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void
|
|||
switch_ivr_play_file(collect->session, NULL, collect->error_file, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
wbreak:
|
||||
|
||||
switch_core_session_rwunlock(collect->session);
|
||||
|
|
|
@ -3934,12 +3934,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess
|
|||
case SWITCH_RTP_CRYPTO_RECV:
|
||||
switch_channel_set_variable(channel, "srtp_remote_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
case SWITCH_RTP_CRYPTO_SEND_RTCP:
|
||||
switch_channel_set_variable(channel, "srtcp_local_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
case SWITCH_RTP_CRYPTO_RECV_RTCP:
|
||||
switch_channel_set_variable(channel, "srtcp_remote_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -3952,12 +3946,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess
|
|||
case SWITCH_RTP_CRYPTO_RECV:
|
||||
switch_channel_set_variable(channel, "srtp_remote_video_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
case SWITCH_RTP_CRYPTO_SEND_RTCP:
|
||||
switch_channel_set_variable(channel, "srtcp_local_video_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
case SWITCH_RTP_CRYPTO_RECV_RTCP:
|
||||
switch_channel_set_variable(channel, "srtcp_remote_video_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -3970,12 +3958,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess
|
|||
case SWITCH_RTP_CRYPTO_RECV:
|
||||
switch_channel_set_variable(channel, "srtp_remote_audio_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
case SWITCH_RTP_CRYPTO_SEND_RTCP:
|
||||
switch_channel_set_variable(channel, "srtcp_local_audio_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
case SWITCH_RTP_CRYPTO_RECV_RTCP:
|
||||
switch_channel_set_variable(channel, "srtcp_remote_audio_crypto_key", (const char *)b64_key);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -550,15 +550,22 @@ SWITCH_DECLARE(const char **) switch_xml_pi(switch_xml_t xml, const char *target
|
|||
switch_xml_root_t root = (switch_xml_root_t) xml;
|
||||
int i = 0;
|
||||
|
||||
if (!root)
|
||||
if (!root) {
|
||||
return (const char **) SWITCH_XML_NIL;
|
||||
while (root->xml.parent)
|
||||
}
|
||||
|
||||
while (root && root->xml.parent) {
|
||||
root = (switch_xml_root_t) root->xml.parent; /* root tag */
|
||||
}
|
||||
|
||||
if (!root || !root->pi) {
|
||||
return (const char **) SWITCH_XML_NIL;
|
||||
}
|
||||
while (root->pi[i] && strcmp(target, root->pi[i][0]))
|
||||
|
||||
while (root->pi[i] && strcmp(target, root->pi[i][0])) {
|
||||
i++; /* find target */
|
||||
}
|
||||
|
||||
return (const char **) ((root->pi[i]) ? root->pi[i] + 1 : SWITCH_XML_NIL);
|
||||
}
|
||||
|
||||
|
@ -1146,7 +1153,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len)
|
|||
return switch_xml_err(root, d, "unclosed <!--");
|
||||
} else if (!strncmp(s, "![CDATA[", 8)) { /* cdata */
|
||||
if ((s = strstr(s, "]]>"))) {
|
||||
if (root && root->cur) {
|
||||
if (root->cur) {
|
||||
root->cur->flags |= SWITCH_XML_CDATA;
|
||||
}
|
||||
switch_xml_char_content(root, d + 8, (s += 2) - d - 10, 'c');
|
||||
|
@ -1213,10 +1220,18 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE * fp)
|
|||
}
|
||||
} while (s && l == SWITCH_XML_BUFSIZE);
|
||||
|
||||
if (!s)
|
||||
if (!s) {
|
||||
return NULL;
|
||||
root = (switch_xml_root_t) switch_xml_parse_str(s, len);
|
||||
}
|
||||
|
||||
if (!(root = (switch_xml_root_t) switch_xml_parse_str(s, len))) {
|
||||
free(s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root->dynamic = 1; /* so we know to free s in switch_xml_free() */
|
||||
|
||||
return &root->xml;
|
||||
}
|
||||
|
||||
|
@ -1232,9 +1247,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
|
|||
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
fstat(fd, &st);
|
||||
|
||||
if (!st.st_size) {
|
||||
if (fstat(fd, &st) == -1 || !st.st_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1243,8 +1257,10 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
|
|||
if (!(0<(l = read(fd, m, st.st_size)))
|
||||
|| !(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) {
|
||||
free(m);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root->dynamic = 1; /* so we know to free s in switch_xml_free() */
|
||||
|
||||
return &root->xml;
|
||||
|
@ -1637,8 +1653,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
|
|||
switch_xml_root_t root;
|
||||
|
||||
if ((fd = open(file, O_RDONLY, 0)) > -1) {
|
||||
fstat(fd, &st);
|
||||
if (!st.st_size) {
|
||||
if (fstat(fd, &st) == -1 || !st.st_size) {
|
||||
close(fd);
|
||||
goto error;
|
||||
}
|
||||
|
@ -1659,6 +1674,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
|
|||
|
||||
root->dynamic = 1;
|
||||
close(fd);
|
||||
|
||||
return &root->xml;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue