Added fixes for crashing upon somebody removing you from their friends. (#171)

Before these fixes, RELATIONSHIP_REMOVE would cause a segfault. My understanding of this, is that RELATIONSHIP_REMOVE's json looks like: {"t":"RELATIONSHIP_REMOVE","s":97,"op":0,"d":{"type":1,"id":"<removed>"}} and this is the primary cause of this problem.

In the original code, json_value *uinfo = json_o_get(rinfo, "user"); would lead to a null pointer being fed into discord_canonize_name as char *name = discord_canonize_name(json_o_str(uinfo, "username")); has no handling for being fed a null pointer. 

Instead of adding in specific null pointer handling, I reworked it to get the ID from the request and to use get_user to get the user from that, instead.
This commit is contained in:
kat 2018-08-21 12:39:25 +01:00 committed by Artem Savkov
parent fd8213fbd9
commit 967df38048
1 changed files with 11 additions and 5 deletions

View File

@ -190,12 +190,15 @@ static void discord_handle_relationship(struct im_connection *ic, json_value *ri
{
discord_data *dd = ic->proto_data;
relationship_type rtype = 0;
json_value *uinfo = json_o_get(rinfo, "user");
char *name = NULL;
json_value *uinfo = NULL;
bee_user_t *bu = NULL;
json_value *tjs = json_o_get(rinfo, "type");
char *name = discord_canonize_name(json_o_str(uinfo, "username"));
bee_user_t *bu = bee_user_by_handle(ic->bee, ic, name);
if (action == ACTION_CREATE) {
uinfo = json_o_get(rinfo, "user");
name = discord_canonize_name(json_o_str(uinfo, "username"));
bu = bee_user_by_handle(ic->bee, ic, name);
rtype = (tjs && tjs->type == json_integer) ? tjs->u.integer : 0;
if (rtype == RELATIONSHIP_FRIENDS) {
@ -206,8 +209,8 @@ static void discord_handle_relationship(struct im_connection *ic, json_value *ri
if (bu) {
bu->data = GINT_TO_POINTER(TRUE);
if (set_getbool(&ic->acc->set, "friendship_mode") == TRUE) {
user_info *uinfo = get_user(dd, name, NULL, SEARCH_NAME);
imcb_buddy_status(ic, name, uinfo->flags, NULL, NULL);
user_info *uinf = get_user(dd, name, NULL, SEARCH_NAME);
imcb_buddy_status(ic, name, uinf->flags, NULL, NULL);
}
}
} else if (rtype == RELATIONSHIP_REQUEST_RECEIVED) {
@ -215,6 +218,9 @@ static void discord_handle_relationship(struct im_connection *ic, json_value *ri
}
} else if (action == ACTION_DELETE) {
user_info *uinf = get_user(dd, json_o_str(rinfo, "id"), NULL, SEARCH_ID);
name = g_strdup(uinf->name);
bu = uinf->user;
if (bu) {
bu->data = GINT_TO_POINTER(FALSE);
if (set_getbool(&ic->acc->set, "friendship_mode") == TRUE) {