1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

database: make log_database_get_previous_chat safer

This commit is contained in:
Michael Vetter 2021-03-25 16:46:18 +01:00
parent e93d4ff331
commit 901f9d3d8c

View File

@ -214,6 +214,8 @@ log_database_get_previous_chat(const gchar* const contact_barejid)
char* query;
const char* jid = connection_get_fulljid();
Jid* myjid = jid_create(jid);
if (!myjid)
return NULL;
if (asprintf(&query, "SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE (`from_jid` = '%s' AND `to_jid` = '%s') OR (`from_jid` = '%s' AND `to_jid` = '%s') ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid) == -1) {
log_error("log_database_get_previous_chat(): SQL query. could not allocate memory");