Skip to content

Commit 9610ac3

Browse files
committed
fix: Return an error instead of crashing on nullptr args in NGC.
1 parent a57c2c8 commit 9610ac3

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

toxcore/tox.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,12 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
25512551
Tox_Err_Conference_Join *error)
25522552
{
25532553
assert(tox != nullptr);
2554+
2555+
if (cookie == nullptr) {
2556+
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_JOIN_NULL);
2557+
return UINT32_MAX;
2558+
}
2559+
25542560
tox_lock(tox);
25552561
const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
25562562
tox_unlock(tox);
@@ -4263,6 +4269,11 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t
42634269
{
42644270
assert(tox != nullptr);
42654271

4272+
if (invite_data == nullptr || name == nullptr) {
4273+
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_INVITE_ACCEPT_NULL);
4274+
return UINT32_MAX;
4275+
}
4276+
42664277
tox_lock(tox);
42674278
const int ret = gc_accept_invite(tox->m->group_handler, friend_number, invite_data, length, name, name_length, password,
42684279
password_length);

toxcore/tox.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,11 @@ typedef enum Tox_Err_Conference_Join {
28912891
*/
28922892
TOX_ERR_CONFERENCE_JOIN_FAIL_SEND,
28932893

2894+
/**
2895+
* The cookie passed was NULL.
2896+
*/
2897+
TOX_ERR_CONFERENCE_JOIN_NULL,
2898+
28942899
} Tox_Err_Conference_Join;
28952900

28962901
const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value);
@@ -4995,6 +5000,11 @@ typedef enum Tox_Err_Group_Invite_Accept {
49955000
*/
49965001
TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND,
49975002

5003+
/**
5004+
* Invite data or name is NULL.
5005+
*/
5006+
TOX_ERR_GROUP_INVITE_ACCEPT_NULL,
5007+
49985008
} Tox_Err_Group_Invite_Accept;
49995009

50005010
const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value);

toxcore/tox_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,9 @@ const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value)
887887

888888
case TOX_ERR_CONFERENCE_JOIN_FAIL_SEND:
889889
return "TOX_ERR_CONFERENCE_JOIN_FAIL_SEND";
890+
891+
case TOX_ERR_CONFERENCE_JOIN_NULL:
892+
return "TOX_ERR_CONFERENCE_JOIN_NULL";
890893
}
891894

892895
return "<invalid Tox_Err_Conference_Join>";
@@ -1448,6 +1451,9 @@ const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept va
14481451

14491452
case TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND:
14501453
return "TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND";
1454+
1455+
case TOX_ERR_GROUP_INVITE_ACCEPT_NULL:
1456+
return "TOX_ERR_GROUP_INVITE_ACCEPT_NULL";
14511457
}
14521458

14531459
return "<invalid Tox_Err_Group_Invite_Accept>";

0 commit comments

Comments
 (0)