Skip to content

Commit

Permalink
Fixed small bugs identified via static analysis (Coverity)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Sep 10, 2024
1 parent f372f4c commit 64e30c0
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 51 deletions.
4 changes: 2 additions & 2 deletions events/janus_gelfevh.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ static int janus_gelfevh_send(char *message) {
if(transport == JANUS_GELFEVH_SOCKET_TYPE_TCP) {
/* TCP */
int out_bytes = 0;
int length = strlen(message);
int length = strlen(message) + 1;
char *buffer = message;
while(length > 0) {
out_bytes = send(sockfd, buffer, length + 1, 0);
out_bytes = send(sockfd, buffer, length, 0);
if(out_bytes <= 0) {
JANUS_LOG(LOG_WARN, "Sending TCP message failed, dropping event: %d (%s)\n", errno, g_strerror(errno));
close(sockfd);
Expand Down
26 changes: 15 additions & 11 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,22 @@ void janus_ice_enforce_interface(const char *ip) {
janus_mutex_unlock(&ice_list_mutex);
}
gboolean janus_ice_is_enforced(const char *ip) {
if(ip == NULL || janus_ice_enforce_list == NULL)
return false;
janus_mutex_lock(&ice_list_mutex);
if(ip == NULL || janus_ice_enforce_list == NULL) {
janus_mutex_unlock(&ice_list_mutex);
return FALSE;
}
GList *temp = janus_ice_enforce_list;
while(temp) {
const char *enforced = (const char *)temp->data;
if(enforced != NULL && strstr(ip, enforced) == ip) {
janus_mutex_unlock(&ice_list_mutex);
return true;
return TRUE;
}
temp = temp->next;
}
janus_mutex_unlock(&ice_list_mutex);
return false;
return FALSE;
}

void janus_ice_ignore_interface(const char *ip) {
Expand All @@ -391,20 +393,22 @@ void janus_ice_ignore_interface(const char *ip) {
janus_mutex_unlock(&ice_list_mutex);
}
gboolean janus_ice_is_ignored(const char *ip) {
if(ip == NULL || janus_ice_ignore_list == NULL)
return false;
janus_mutex_lock(&ice_list_mutex);
if(ip == NULL || janus_ice_ignore_list == NULL) {
janus_mutex_unlock(&ice_list_mutex);
return FALSE;
}
GList *temp = janus_ice_ignore_list;
while(temp) {
const char *ignored = (const char *)temp->data;
if(ignored != NULL && strstr(ip, ignored) == ip) {
janus_mutex_unlock(&ice_list_mutex);
return true;
return TRUE;
}
temp = temp->next;
}
janus_mutex_unlock(&ice_list_mutex);
return false;
return FALSE;
}


Expand All @@ -418,7 +422,7 @@ int janus_ice_get_event_stats_period(void) {
}

/* How to handle media statistic events (one per media or one per peerConnection) */
static gboolean janus_ice_event_combine_media_stats = false;
static gboolean janus_ice_event_combine_media_stats = FALSE;
void janus_ice_event_set_combine_media_stats(gboolean combine_media_stats_to_one_event) {
janus_ice_event_combine_media_stats = combine_media_stats_to_one_event;
}
Expand Down Expand Up @@ -3155,7 +3159,7 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
}
if(rtcp_ssrc == 0) {
if(!fallback) {
fallback = true;
fallback = TRUE;
continue;
}
/* No SSRC, maybe an empty RR? */
Expand Down Expand Up @@ -3233,7 +3237,7 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
}
if(rtcp_ssrc == 0) {
if(!fallback) {
fallback = true;
fallback = TRUE;
continue;
}
/* No SSRC, maybe an empty RR? */
Expand Down
3 changes: 3 additions & 0 deletions plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -7298,6 +7298,7 @@ static void *janus_audiobridge_handler(void *data) {
if(error_code != 0) {
janus_mutex_unlock(&audiobridge->mutex);
janus_refcount_decrease(&audiobridge->ref);
janus_mutex_unlock(&rooms_mutex);
goto error;
}
admin = TRUE;
Expand All @@ -7311,13 +7312,15 @@ static void *janus_audiobridge_handler(void *data) {
if(error_code != 0) {
janus_mutex_unlock(&audiobridge->mutex);
janus_refcount_decrease(&audiobridge->ref);
janus_mutex_unlock(&rooms_mutex);
goto error;
}
const char *group_name = json_string_value(json_object_get(root, "group"));
group = GPOINTER_TO_UINT(g_hash_table_lookup(audiobridge->groups, group_name));
if(group == 0) {
janus_mutex_unlock(&audiobridge->mutex);
janus_refcount_decrease(&audiobridge->ref);
janus_mutex_unlock(&rooms_mutex);
JANUS_LOG(LOG_ERR, "No such group (%s)\n", group_name);
error_code = JANUS_AUDIOBRIDGE_ERROR_NO_SUCH_GROUP;
g_snprintf(error_cause, 512, "No such group (%s)", group_name);
Expand Down
18 changes: 12 additions & 6 deletions plugins/janus_duktape.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,11 +1848,12 @@ int janus_duktape_get_version(void) {
/* Check if the JS script wants to override this method and return info itself */
if(has_get_version) {
/* Yep, pass the request to the JS script and return the info */
janus_mutex_lock(&duktape_mutex);
if(duktape_script_version != -1) {
/* Unless we asked already */
janus_mutex_unlock(&duktape_mutex);
return duktape_script_version;
}
janus_mutex_lock(&duktape_mutex);
duk_idx_t thr_idx = duk_push_thread(duktape_ctx);
duk_context *t = duk_get_context(duktape_ctx, thr_idx);
duk_get_global_string(t, "getVersion");
Expand All @@ -1879,11 +1880,12 @@ const char *janus_duktape_get_version_string(void) {
/* Check if the JS script wants to override this method and return info itself */
if(has_get_version_string) {
/* Yep, pass the request to the JS script and return the info */
janus_mutex_lock(&duktape_mutex);
if(duktape_script_version_string != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&duktape_mutex);
return duktape_script_version_string;
}
janus_mutex_lock(&duktape_mutex);
duk_idx_t thr_idx = duk_push_thread(duktape_ctx);
duk_context *t = duk_get_context(duktape_ctx, thr_idx);
duk_get_global_string(t, "getVersionString");
Expand Down Expand Up @@ -1912,11 +1914,12 @@ const char *janus_duktape_get_description(void) {
/* Check if the JS script wants to override this method and return info itself */
if(has_get_description) {
/* Yep, pass the request to the JS script and return the info */
janus_mutex_lock(&duktape_mutex);
if(duktape_script_description != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&duktape_mutex);
return duktape_script_description;
}
janus_mutex_lock(&duktape_mutex);
duk_idx_t thr_idx = duk_push_thread(duktape_ctx);
duk_context *t = duk_get_context(duktape_ctx, thr_idx);
duk_get_global_string(t, "getDescription");
Expand Down Expand Up @@ -1945,11 +1948,12 @@ const char *janus_duktape_get_name(void) {
/* Check if the JS script wants to override this method and return info itself */
if(has_get_name) {
/* Yep, pass the request to the JS script and return the info */
janus_mutex_lock(&duktape_mutex);
if(duktape_script_name != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&duktape_mutex);
return duktape_script_name;
}
janus_mutex_lock(&duktape_mutex);
duk_idx_t thr_idx = duk_push_thread(duktape_ctx);
duk_context *t = duk_get_context(duktape_ctx, thr_idx);
duk_get_global_string(t, "getName");
Expand Down Expand Up @@ -1978,11 +1982,12 @@ const char *janus_duktape_get_author(void) {
/* Check if the JS script wants to override this method and return info itself */
if(has_get_author) {
/* Yep, pass the request to the JS script and return the info */
janus_mutex_lock(&duktape_mutex);
if(duktape_script_author != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&duktape_mutex);
return duktape_script_author;
}
janus_mutex_lock(&duktape_mutex);
duk_idx_t thr_idx = duk_push_thread(duktape_ctx);
duk_context *t = duk_get_context(duktape_ctx, thr_idx);
duk_get_global_string(t, "getAuthor");
Expand Down Expand Up @@ -2011,11 +2016,12 @@ const char *janus_duktape_get_package(void) {
/* Check if the JS script wants to override this method and return info itself */
if(has_get_package) {
/* Yep, pass the request to the JS script and return the info */
janus_mutex_lock(&duktape_mutex);
if(duktape_script_package != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&duktape_mutex);
return duktape_script_package;
}
janus_mutex_lock(&duktape_mutex);
duk_idx_t thr_idx = duk_push_thread(duktape_ctx);
duk_context *t = duk_get_context(duktape_ctx, thr_idx);
duk_get_global_string(t, "getPackage");
Expand Down
18 changes: 12 additions & 6 deletions plugins/janus_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1617,11 +1617,12 @@ int janus_lua_get_version(void) {
/* Check if the Lua script wants to override this method and return info itself */
if(has_get_version) {
/* Yep, pass the request to the Lua script and return the info */
janus_mutex_lock(&lua_mutex);
if(lua_script_version != -1) {
/* Unless we asked already */
janus_mutex_unlock(&lua_mutex);
return lua_script_version;
}
janus_mutex_lock(&lua_mutex);
lua_State *t = lua_newthread(lua_state);
lua_getglobal(t, "getVersion");
lua_call(t, 0, 1);
Expand All @@ -1638,11 +1639,12 @@ const char *janus_lua_get_version_string(void) {
/* Check if the Lua script wants to override this method and return info itself */
if(has_get_version_string) {
/* Yep, pass the request to the Lua script and return the info */
janus_mutex_lock(&lua_mutex);
if(lua_script_version_string != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&lua_mutex);
return lua_script_version_string;
}
janus_mutex_lock(&lua_mutex);
lua_State *t = lua_newthread(lua_state);
lua_getglobal(t, "getVersionString");
lua_call(t, 0, 1);
Expand All @@ -1661,11 +1663,12 @@ const char *janus_lua_get_description(void) {
/* Check if the Lua script wants to override this method and return info itself */
if(has_get_description) {
/* Yep, pass the request to the Lua script and return the info */
janus_mutex_lock(&lua_mutex);
if(lua_script_description != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&lua_mutex);
return lua_script_description;
}
janus_mutex_lock(&lua_mutex);
lua_State *t = lua_newthread(lua_state);
lua_getglobal(t, "getDescription");
lua_call(t, 0, 1);
Expand All @@ -1684,11 +1687,12 @@ const char *janus_lua_get_name(void) {
/* Check if the Lua script wants to override this method and return info itself */
if(has_get_name) {
/* Yep, pass the request to the Lua script and return the info */
janus_mutex_lock(&lua_mutex);
if(lua_script_name != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&lua_mutex);
return lua_script_name;
}
janus_mutex_lock(&lua_mutex);
lua_State *t = lua_newthread(lua_state);
lua_getglobal(t, "getName");
lua_call(t, 0, 1);
Expand All @@ -1707,11 +1711,12 @@ const char *janus_lua_get_author(void) {
/* Check if the Lua script wants to override this method and return info itself */
if(has_get_author) {
/* Yep, pass the request to the Lua script and return the info */
janus_mutex_lock(&lua_mutex);
if(lua_script_author != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&lua_mutex);
return lua_script_author;
}
janus_mutex_lock(&lua_mutex);
lua_State *t = lua_newthread(lua_state);
lua_getglobal(t, "getAuthor");
lua_call(t, 0, 1);
Expand All @@ -1730,11 +1735,12 @@ const char *janus_lua_get_package(void) {
/* Check if the Lua script wants to override this method and return info itself */
if(has_get_package) {
/* Yep, pass the request to the Lua script and return the info */
janus_mutex_lock(&lua_mutex);
if(lua_script_package != NULL) {
/* Unless we asked already */
janus_mutex_unlock(&lua_mutex);
return lua_script_package;
}
janus_mutex_lock(&lua_mutex);
lua_State *t = lua_newthread(lua_state);
lua_getglobal(t, "getPackage");
lua_call(t, 0, 1);
Expand Down
2 changes: 1 addition & 1 deletion plugins/janus_sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -5135,7 +5135,7 @@ void janus_sip_sofia_callback(nua_event_t event, int status, char const *phrase,
break;
case nua_i_state:;
tagi_t const *ti = tl_find(tags, nutag_callstate);
enum nua_callstate callstate = ti ? ti->t_value : -1;
enum nua_callstate callstate = ti ? ti->t_value : nua_callstate_init;
JANUS_LOG(LOG_VERB, "[%s][%s]: %d %s, call state [%s]\n", session->account.username, nua_event_name(event), status, phrase ? phrase : "??", nua_callstate_name(callstate));
/* There are several call states, but we care about the terminated state in order to send the 'hangup' event
* and the proceeding state in order to send the 'proceeding' event so the client can play a ringback tone for
Expand Down
15 changes: 8 additions & 7 deletions plugins/janus_videocall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,12 +1136,6 @@ static void *janus_videocall_handler(void *data) {
janus_mutex_unlock(&sessions_mutex);
} else if(!strcasecmp(request_text, "register")) {
/* Map this handle to a username */
if(session->username != NULL) {
JANUS_LOG(LOG_ERR, "Already registered (%s)\n", session->username);
error_code = JANUS_VIDEOCALL_ERROR_ALREADY_REGISTERED;
g_snprintf(error_cause, 512, "Already registered (%s)", session->username);
goto error;
}
JANUS_VALIDATE_JSON_OBJECT(root, username_parameters,
error_code, error_cause, TRUE,
JANUS_VIDEOCALL_ERROR_MISSING_ELEMENT, JANUS_VIDEOCALL_ERROR_INVALID_ELEMENT);
Expand All @@ -1150,6 +1144,13 @@ static void *janus_videocall_handler(void *data) {
json_t *username = json_object_get(root, "username");
const char *username_text = json_string_value(username);
janus_mutex_lock(&sessions_mutex);
if(session->username != NULL) {
janus_mutex_unlock(&sessions_mutex);
JANUS_LOG(LOG_ERR, "Already registered (%s)\n", session->username);
error_code = JANUS_VIDEOCALL_ERROR_ALREADY_REGISTERED;
g_snprintf(error_cause, 512, "Already registered (%s)", session->username);
goto error;
}
if(g_hash_table_lookup(usernames, username_text) != NULL) {
janus_mutex_unlock(&sessions_mutex);
JANUS_LOG(LOG_ERR, "Username '%s' already taken\n", username_text);
Expand Down Expand Up @@ -1354,7 +1355,7 @@ static void *janus_videocall_handler(void *data) {
g_snprintf(error_cause, 512, "Error parsing answer: %s", error_str);
goto error;
}
JANUS_LOG(LOG_VERB, "%s is accepting a call from %s\n", session->username, peer->username);
JANUS_LOG(LOG_VERB, "%s is accepting a call from %s\n", session->username, peer ? peer->username : "??");
JANUS_LOG(LOG_VERB, "This is involving a negotiation (%s) as well:\n%s\n", msg_sdp_type, msg_sdp);
session->has_audio = (strstr(msg_sdp, "m=audio") != NULL);
session->has_video = (strstr(msg_sdp, "m=video") != NULL);
Expand Down
4 changes: 2 additions & 2 deletions postprocessing/janus-pp-rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,8 +1660,8 @@ static gint janus_pp_skew_compensate_audio(janus_pp_frame_packet *pkt, janus_pp_
exit_status = -1;
} else {
context->target_ts = 0;
/* Do not execute analysis for out of order packets or multi-packets frame */
if (context->last_seq == context->prev_seq + 1 && context->last_ts != context->prev_ts) {
/* Do not execute analysis for out of order packets or multi-packets frame or if pts < start_time */
if (context->last_seq == context->prev_seq + 1 && context->last_ts != context->prev_ts && pts >= context->start_time) {
/* Evaluate the local RTP timestamp according to the local clock */
guint64 expected_ts = ((pts - context->start_time) * akhz) + context->start_ts;
/* Evaluate current delay */
Expand Down
8 changes: 5 additions & 3 deletions postprocessing/pp-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ static uint32_t janus_pp_h264_eg_decode(uint8_t *base, uint32_t *offset) {
while(janus_pp_h264_eg_getbit(base, (*offset)++) == 0)
zeros++;
uint32_t res = 1 << zeros;
int32_t i = 0;
for(i=zeros-1; i>=0; i--) {
res |= janus_pp_h264_eg_getbit(base, (*offset)++) << i;
if(zeros > 0) {
int32_t i = 0;
for(i=zeros-1; i>=0; i--) {
res |= janus_pp_h264_eg_getbit(base, (*offset)++) << i;
}
}
return res-1;
}
Expand Down
8 changes: 5 additions & 3 deletions postprocessing/pp-h265.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ static uint32_t janus_pp_h265_eg_decode(uint8_t *base, uint32_t *offset) {
while(janus_pp_h265_eg_getbit(base, (*offset)++) == 0)
zeros++;
uint32_t res = 1 << zeros;
int32_t i = 0;
for(i=zeros-1; i>=0; i--) {
res |= janus_pp_h265_eg_getbit(base, (*offset)++) << i;
if(zeros > 0) {
int32_t i = 0;
for(i=zeros-1; i>=0; i--) {
res |= janus_pp_h265_eg_getbit(base, (*offset)++) << i;
}
}
return res-1;
}
Expand Down
10 changes: 8 additions & 2 deletions postprocessing/pp-webm.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,14 @@ int janus_pp_webm_process(FILE *file, janus_pp_frame_packet *list, gboolean vp8,
}
}
/* Frame manipulation */
memcpy(received_frame + frameLen, buffer, len);
frameLen += len;
if(len > 0) {
if(frameLen + len + AV_INPUT_BUFFER_PADDING_SIZE > numBytes) {
JANUS_LOG(LOG_WARN, "Frame exceeds buffer size...\n");
} else {
memcpy(received_frame + frameLen, buffer, len);
frameLen += len;
}
}
if(len == 0)
break;
/* Check if timestamp changes: marker bit is not mandatory, and may be lost as well */
Expand Down
Loading

0 comments on commit 64e30c0

Please sign in to comment.