Add some missing null checks

This commit is contained in:
jfreegman 2021-12-06 16:57:07 -05:00
parent d930ecca4c
commit ce268c2f82
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 31 additions and 6 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -578,7 +578,13 @@ NEW_MULTIPARTED:
/* 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;

View File

@ -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;
}
@ -1323,10 +1323,15 @@ 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;
}
@ -1334,15 +1339,16 @@ static bool call_prepare_transmission(ToxAVCall *call)
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;
}
@ -1350,7 +1356,7 @@ static bool call_prepare_transmission(ToxAVCall *call)
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;
}

View File

@ -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);