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 449d7c8 commit 08a7d88
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/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
18 changes: 11 additions & 7 deletions src/ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ 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;
Expand All @@ -380,7 +382,7 @@ gboolean janus_ice_is_enforced(const char *ip) {
temp = temp->next;
}
janus_mutex_unlock(&ice_list_mutex);
return false;
return FALSE;
}

void janus_ice_ignore_interface(const char *ip) {
Expand All @@ -395,9 +397,11 @@ 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;
Expand All @@ -408,7 +412,7 @@ gboolean janus_ice_is_ignored(const char *ip) {
temp = temp->next;
}
janus_mutex_unlock(&ice_list_mutex);
return false;
return FALSE;
}


Expand All @@ -422,7 +426,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
3 changes: 3 additions & 0 deletions src/plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -7374,6 +7374,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 @@ -7387,13 +7388,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 src/plugins/janus_duktape.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,11 +1843,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 @@ -1874,11 +1875,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 @@ -1907,11 +1909,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 @@ -1940,11 +1943,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 @@ -1973,11 +1977,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 @@ -2006,11 +2011,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 src/plugins/janus_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,11 +1612,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 @@ -1633,11 +1634,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 @@ -1656,11 +1658,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 @@ -1679,11 +1682,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 @@ -1702,11 +1706,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 @@ -1725,11 +1730,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 src/plugins/janus_sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -5143,7 +5143,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 src/plugins/janus_videocall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,12 +1137,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 @@ -1151,6 +1145,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 @@ -1564,7 +1565,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 an update from %s\n", session->username, peer->username);
JANUS_LOG(LOG_VERB, "%s is accepting an update from %s\n", session->username, peer ? peer->username : "??");
session->has_audio = (strstr(msg_sdp, "m=audio") != NULL);
session->has_video = (strstr(msg_sdp, "m=video") != NULL);
session->has_data = (strstr(msg_sdp, "DTLS/SCTP") != NULL);
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -3304,10 +3304,10 @@ static janus_videoroom_subscriber_stream *janus_videoroom_subscriber_stream_add_
GList *temp = subscriber->streams;
while(temp) {
stream = (janus_videoroom_subscriber_stream *)temp->data;
janus_mutex_lock(&ps->subscribers_mutex);
janus_videoroom_publisher_stream *stream_ps = stream->publisher_streams ? stream->publisher_streams->data : NULL;
if(stream_ps != NULL && stream_ps->type == ps->type && stream->type == JANUS_VIDEOROOM_MEDIA_DATA) {
/* We already have a datachannel m-line, no need for others: just update the subscribers list */
janus_mutex_lock(&ps->subscribers_mutex);
if(g_slist_find(ps->subscribers, stream) == NULL && g_slist_find(stream->publisher_streams, ps) == NULL) {
ps->subscribers = g_slist_append(ps->subscribers, stream);
stream->publisher_streams = g_slist_append(stream->publisher_streams, ps);
Expand Down Expand Up @@ -3340,6 +3340,7 @@ static janus_videoroom_subscriber_stream *janus_videoroom_subscriber_stream_add_
janus_mutex_unlock(&ps->subscribers_mutex);
return NULL;
}
janus_mutex_unlock(&ps->subscribers_mutex);
if(stream_ps == NULL && stream->type == ps->type) {
/* There's an empty m-line of the right type, check if codecs match */
if(stream->type == JANUS_VIDEOROOM_MEDIA_DATA ||
Expand Down Expand Up @@ -4512,6 +4513,7 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
janus_mutex_unlock(&sessions_mutex);
/* Show the participant/room info, if any */
json_t *info = json_object();
janus_mutex_lock(&session->mutex);
if(session->participant) {
if(session->participant_type == janus_videoroom_p_type_none) {
json_object_set_new(info, "type", json_string("none"));
Expand Down Expand Up @@ -4604,6 +4606,7 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
}
json_object_set_new(info, "hangingup", json_integer(g_atomic_int_get(&session->hangingup)));
json_object_set_new(info, "destroyed", json_integer(g_atomic_int_get(&session->destroyed)));
janus_mutex_unlock(&session->mutex);
janus_refcount_decrease(&session->ref);
return info;
}
Expand Down
4 changes: 2 additions & 2 deletions src/postprocessing/janus-pp-rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,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
2 changes: 1 addition & 1 deletion src/postprocessing/pp-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ 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;
uint32_t i = 0;
for(i=zeros-1; i>=0; i--) {
res |= janus_pp_h264_eg_getbit(base, (*offset)++) << i;
}
Expand Down
2 changes: 1 addition & 1 deletion src/postprocessing/pp-h265.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ 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;
uint32_t i = 0;
for(i=zeros-1; i>=0; i--) {
res |= janus_pp_h265_eg_getbit(base, (*offset)++) << i;
}
Expand Down
10 changes: 8 additions & 2 deletions src/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 08a7d88

Please sign in to comment.