Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return an error instead of crashing on nullptr args in NGC. #2783

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading