0
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-07-26 12:14:28 -04:00

stanza: guard mallocs

If this happens we have more serious problems :-)
But anyways..
This commit is contained in:
Michael Vetter 2021-03-25 16:14:40 +01:00
parent d23c3dd065
commit f81ed759f5

View File

@ -288,11 +288,13 @@ void
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata) iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
{ {
ProfIqHandler* handler = malloc(sizeof(ProfIqHandler)); ProfIqHandler* handler = malloc(sizeof(ProfIqHandler));
handler->func = func; if (handler) {
handler->free_func = free_func; handler->func = func;
handler->userdata = userdata; handler->free_func = free_func;
handler->userdata = userdata;
g_hash_table_insert(id_handlers, strdup(id), handler); g_hash_table_insert(id_handlers, strdup(id), handler);
}
} }
void void
@ -481,15 +483,17 @@ iq_room_info_request(const char* const room, gboolean display_result)
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, room, NULL); xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, room, NULL);
ProfRoomInfoData* cb_data = malloc(sizeof(ProfRoomInfoData)); ProfRoomInfoData* cb_data = malloc(sizeof(ProfRoomInfoData));
cb_data->room = strdup(room); if (cb_data) {
cb_data->display = display_result; cb_data->room = strdup(room);
cb_data->display = display_result;
iq_id_handler_add(id, _room_info_response_id_handler, (ProfIqFreeCallback)_iq_free_room_data, cb_data); iq_id_handler_add(id, _room_info_response_id_handler, (ProfIqFreeCallback)_iq_free_room_data, cb_data);
iq_send_stanza(iq);
xmpp_stanza_release(iq);
}
free(id); free(id);
iq_send_stanza(iq);
xmpp_stanza_release(iq);
} }
void void
@ -667,13 +671,15 @@ iq_room_affiliation_list(const char* const room, char* affiliation, bool show_ui
const char* id = xmpp_stanza_get_id(iq); const char* id = xmpp_stanza_get_id(iq);
ProfAffiliationList* affiliation_list = malloc(sizeof(ProfAffiliationList)); ProfAffiliationList* affiliation_list = malloc(sizeof(ProfAffiliationList));
affiliation_list->affiliation = strdup(affiliation); if (affiliation_list) {
affiliation_list->show_ui_message = show_ui_message; affiliation_list->affiliation = strdup(affiliation);
affiliation_list->show_ui_message = show_ui_message;
iq_id_handler_add(id, _room_affiliation_list_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_list, affiliation_list); iq_id_handler_add(id, _room_affiliation_list_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_list, affiliation_list);
iq_send_stanza(iq); iq_send_stanza(iq);
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
}
} }
void void
@ -699,13 +705,15 @@ iq_room_affiliation_set(const char* const room, const char* const jid, char* aff
const char* id = xmpp_stanza_get_id(iq); const char* id = xmpp_stanza_get_id(iq);
ProfPrivilegeSet* affiliation_set = malloc(sizeof(struct privilege_set_t)); ProfPrivilegeSet* affiliation_set = malloc(sizeof(struct privilege_set_t));
affiliation_set->item = strdup(jid); if (affiliation_set) {
affiliation_set->privilege = strdup(affiliation); affiliation_set->item = strdup(jid);
affiliation_set->privilege = strdup(affiliation);
iq_id_handler_add(id, _room_affiliation_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, affiliation_set); iq_id_handler_add(id, _room_affiliation_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, affiliation_set);
iq_send_stanza(iq); iq_send_stanza(iq);
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
}
} }
void void
@ -718,13 +726,15 @@ iq_room_role_set(const char* const room, const char* const nick, char* role,
const char* id = xmpp_stanza_get_id(iq); const char* id = xmpp_stanza_get_id(iq);
struct privilege_set_t* role_set = malloc(sizeof(ProfPrivilegeSet)); struct privilege_set_t* role_set = malloc(sizeof(ProfPrivilegeSet));
role_set->item = strdup(nick); if (role_set) {
role_set->privilege = strdup(role); role_set->item = strdup(nick);
role_set->privilege = strdup(role);
iq_id_handler_add(id, _room_role_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, role_set); iq_id_handler_add(id, _room_role_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, role_set);
iq_send_stanza(iq); iq_send_stanza(iq);
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
}
} }
void void
@ -2162,27 +2172,29 @@ _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata
if (name || category || type) { if (name || category || type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t)); DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
if (name) { if (identity) {
identity->name = strdup(name); if (name) {
ProfMucWin* mucwin = wins_get_muc(cb_data->room); identity->name = strdup(name);
if (mucwin) { ProfMucWin* mucwin = wins_get_muc(cb_data->room);
mucwin->room_name = strdup(name); if (mucwin) {
mucwin->room_name = strdup(name);
}
} else {
identity->name = NULL;
}
if (category) {
identity->category = strdup(category);
} else {
identity->category = NULL;
}
if (type) {
identity->type = strdup(type);
} else {
identity->type = NULL;
} }
} else {
identity->name = NULL;
}
if (category) {
identity->category = strdup(category);
} else {
identity->category = NULL;
}
if (type) {
identity->type = strdup(type);
} else {
identity->type = NULL;
}
identities = g_slist_append(identities, identity); identities = g_slist_append(identities, identity);
}
} }
} }
@ -2309,23 +2321,25 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
if (name || category || type) { if (name || category || type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t)); DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
if (name) { if (identity) {
identity->name = strdup(name); if (name) {
} else { identity->name = strdup(name);
identity->name = NULL; } else {
} identity->name = NULL;
if (category) { }
identity->category = strdup(category); if (category) {
} else { identity->category = strdup(category);
identity->category = NULL; } else {
} identity->category = NULL;
if (type) { }
identity->type = strdup(type); if (type) {
} else { identity->type = strdup(type);
identity->type = NULL; } else {
} identity->type = NULL;
}
identities = g_slist_append(identities, identity); identities = g_slist_append(identities, identity);
}
} }
} }
@ -2491,14 +2505,16 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
if (item_jid) { if (item_jid) {
DiscoItem* item = malloc(sizeof(struct disco_item_t)); DiscoItem* item = malloc(sizeof(struct disco_item_t));
item->jid = strdup(item_jid); if (item) {
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); item->jid = strdup(item_jid);
if (item_name) { const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
item->name = strdup(item_name); if (item_name) {
} else { item->name = strdup(item_name);
item->name = NULL; } else {
item->name = NULL;
}
items = g_slist_append(items, item);
} }
items = g_slist_append(items, item);
} }
} }
@ -2578,10 +2594,12 @@ iq_mam_request(ProfChatWin* win)
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, datestr, NULL); xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, datestr, NULL);
MamRsmUserdata* data = malloc(sizeof(MamRsmUserdata)); MamRsmUserdata* data = malloc(sizeof(MamRsmUserdata));
data->datestr = strdup(datestr); if (data) {
data->barejid = strdup(win->barejid); data->datestr = strdup(datestr);
data->barejid = strdup(win->barejid);
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, NULL, data); iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, NULL, data);
}
g_free(datestr); g_free(datestr);
g_date_time_unref(timestamp); g_date_time_unref(timestamp);