Skip to content

Commit

Permalink
Add some missing null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Dec 6, 2021
1 parent d930ecc commit ce268c2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb,
Mono_Time *bwc_mono_time)
{
BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1);

if (retu == nullptr) {
return nullptr;
}

LOGGER_DEBUG(m->log, "Creating bandwidth controller");
retu->mcb = mcb;
retu->mcb_user_data = mcb_user_data;
Expand Down
4 changes: 4 additions & 0 deletions toxav/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ bool rb_empty(const RingBuffer *b)
*/
void *rb_write(RingBuffer *b, void *p)
{
if (b == nullptr) {
return p;
}

void *rc = nullptr;

if ((b->end + 1) % b->size == b->start) { /* full */
Expand Down
8 changes: 7 additions & 1 deletion toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ static int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t
/* Store message.
*/
session->mp = new_message(&header, header.data_length_lower, data + RTP_HEADER_SIZE, length - RTP_HEADER_SIZE);
memmove(session->mp->data + header.offset_lower, session->mp->data, session->mp->len);

if (session->mp != nullptr) {
memmove(session->mp->data + header.offset_lower, session->mp->data, session->mp->len);
} else {
LOGGER_WARNING(m->log, "new_message() returned a null pointer");
return -1;
}
}

return 0;
Expand Down
16 changes: 11 additions & 5 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ static bool call_prepare_transmission(ToxAVCall *call)

ToxAV *av = call->av;

if (!av->acb && !av->vcb) {
if (av->acb == nullptr && av->vcb == nullptr) {
/* It makes no sense to have CSession without callbacks */
return false;
}
Expand All @@ -1323,34 +1323,40 @@ static bool call_prepare_transmission(ToxAVCall *call)
/* Prepare bwc */
call->bwc = bwc_new(av->m, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time);

if (call->bwc == nullptr) {
LOGGER_ERROR(av->m->log, "Failed to create new bwc");
goto FAILURE;
}

{ /* Prepare audio */
call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data);

if (!call->audio) {
if (call->audio == nullptr) {
LOGGER_ERROR(av->m->log, "Failed to create audio codec session");
goto FAILURE;
}

call->audio_rtp = rtp_new(RTP_TYPE_AUDIO, av->m, av->tox, call->friend_number, call->bwc,
call->audio, ac_queue_message);

if (!call->audio_rtp) {
if (call->audio_rtp == nullptr) {
LOGGER_ERROR(av->m->log, "Failed to create audio rtp session");
goto FAILURE;
}
}

{ /* Prepare video */
call->video = vc_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data);

if (!call->video) {
if (call->video == nullptr) {
LOGGER_ERROR(av->m->log, "Failed to create video codec session");
goto FAILURE;
}

call->video_rtp = rtp_new(RTP_TYPE_VIDEO, av->m, av->tox, call->friend_number, call->bwc,
call->video, vc_queue_message);

if (!call->video_rtp) {
if (call->video_rtp == nullptr) {
LOGGER_ERROR(av->m->log, "Failed to create video rtp session");
goto FAILURE;
}
Expand Down
4 changes: 4 additions & 0 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,10 @@ static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t fri
{
Group_c *g = get_group_c(g_c, groupnumber);

if (g == nullptr) {
return false;
}

const bool member = (g->status == GROUPCHAT_STATUS_CONNECTED);

VLA(uint8_t, response, member ? INVITE_MEMBER_PACKET_SIZE : INVITE_ACCEPT_PACKET_SIZE);
Expand Down

0 comments on commit ce268c2

Please sign in to comment.