Skip to content

Commit

Permalink
fix: Return an error instead of crashing on nullptr args in NGC.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Nov 8, 2024
1 parent a57c2c8 commit 9610ac3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,12 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
Tox_Err_Conference_Join *error)
{
assert(tox != nullptr);

if (cookie == nullptr) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_JOIN_NULL);
return UINT32_MAX;
}

tox_lock(tox);
const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
tox_unlock(tox);
Expand Down Expand Up @@ -4263,6 +4269,11 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t
{
assert(tox != nullptr);

if (invite_data == nullptr || name == nullptr) {
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_INVITE_ACCEPT_NULL);
return UINT32_MAX;
}

tox_lock(tox);
const int ret = gc_accept_invite(tox->m->group_handler, friend_number, invite_data, length, name, name_length, password,
password_length);
Expand Down
10 changes: 10 additions & 0 deletions toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,11 @@ typedef enum Tox_Err_Conference_Join {
*/
TOX_ERR_CONFERENCE_JOIN_FAIL_SEND,

/**
* The cookie passed was NULL.
*/
TOX_ERR_CONFERENCE_JOIN_NULL,

} Tox_Err_Conference_Join;

const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value);
Expand Down Expand Up @@ -4995,6 +5000,11 @@ typedef enum Tox_Err_Group_Invite_Accept {
*/
TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND,

/**
* Invite data or name is NULL.
*/
TOX_ERR_GROUP_INVITE_ACCEPT_NULL,

} Tox_Err_Group_Invite_Accept;

const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value);
Expand Down
6 changes: 6 additions & 0 deletions toxcore/tox_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value)

case TOX_ERR_CONFERENCE_JOIN_FAIL_SEND:
return "TOX_ERR_CONFERENCE_JOIN_FAIL_SEND";

case TOX_ERR_CONFERENCE_JOIN_NULL:
return "TOX_ERR_CONFERENCE_JOIN_NULL";
}

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

case TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND:
return "TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND";

case TOX_ERR_GROUP_INVITE_ACCEPT_NULL:
return "TOX_ERR_GROUP_INVITE_ACCEPT_NULL";
}

return "<invalid Tox_Err_Group_Invite_Accept>";
Expand Down

0 comments on commit 9610ac3

Please sign in to comment.