fix(autocomplete): guard history completion safely
All checks were successful
CI Code / Check spelling (pull_request) Successful in 12s
CI Code / Check coding style (pull_request) Successful in 23s
CI Code / Code Coverage (pull_request) Successful in 3m40s
CI Code / Linux (debian) (pull_request) Successful in 5m14s
CI Code / Linux (ubuntu) (pull_request) Successful in 5m20s
CI Code / Linux (arch) (pull_request) Successful in 7m23s
All checks were successful
CI Code / Check spelling (pull_request) Successful in 12s
CI Code / Check coding style (pull_request) Successful in 23s
CI Code / Code Coverage (pull_request) Successful in 3m40s
CI Code / Linux (debian) (pull_request) Successful in 5m14s
CI Code / Linux (ubuntu) (pull_request) Successful in 5m20s
CI Code / Linux (arch) (pull_request) Successful in 7m23s
Prevent autocomplete crashes on asset failures when executing history subcommands without an active connection by validating the session state beforehand. Standardize JID resolution across command handlers to ensure consistent contact lookup behavior. Use auto_gchar gchar instead of GString for performance and readability purposes.
This commit is contained in:
@@ -1866,10 +1866,12 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
|||||||
}
|
}
|
||||||
|
|
||||||
gchar* history_jid_subcmds[] = { "/history verify", "/history export", "/history import" };
|
gchar* history_jid_subcmds[] = { "/history verify", "/history export", "/history import" };
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(history_jid_subcmds); i++) {
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
result = autocomplete_param_with_func(input, history_jid_subcmds[i], roster_barejid_autocomplete, previous, NULL);
|
for (size_t i = 0; i < ARRAY_SIZE(history_jid_subcmds); i++) {
|
||||||
if (result) {
|
result = autocomplete_param_with_func(input, history_jid_subcmds[i], roster_barejid_autocomplete, previous, NULL);
|
||||||
return result;
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2045,14 +2047,14 @@ _disco_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
|||||||
{
|
{
|
||||||
char* result = NULL;
|
char* result = NULL;
|
||||||
result = autocomplete_param_with_ac(input, "/disco", disco_ac, TRUE, previous);
|
result = autocomplete_param_with_ac(input, "/disco", disco_ac, TRUE, previous);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = _roster_jid_autocomplete(input, "/disco info", previous);
|
result = _roster_jid_autocomplete(input, "/disco info", previous);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = _roster_jid_autocomplete(input, "/disco items", previous);
|
result = _roster_jid_autocomplete(input, "/disco items", previous);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -3735,7 +3737,7 @@ _win_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* unquoted = strip_arg_quotes(input);
|
char* unquoted = strip_arg_quotes(input);
|
||||||
result = autocomplete_param_with_func(unquoted, "/win", roster_contact_autocomplete, previous, NULL);
|
result = _roster_jid_autocomplete(input, "/win", previous);
|
||||||
free(unquoted);
|
free(unquoted);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -4070,13 +4072,13 @@ _invite_autocomplete(ProfWin* window, const char* const input, gboolean previous
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = _roster_jid_autocomplete(input, "/invite send", previous);
|
result = _roster_jid_autocomplete(input, "/invite send", previous);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = autocomplete_param_with_func(input, "/invite decline", muc_invites_find, previous, NULL);
|
result = autocomplete_param_with_func(input, "/invite decline", muc_invites_find, previous, NULL);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -4092,37 +4094,37 @@ _status_autocomplete(ProfWin* window, const char* const input, gboolean previous
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// complete with: online, away etc.
|
// complete with: online, away etc.
|
||||||
result = autocomplete_param_with_ac(input, "/status set", account_status_ac, TRUE, previous);
|
result = autocomplete_param_with_ac(input, "/status set", account_status_ac, TRUE, previous);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove quote character before and after names when doing autocomplete
|
// Remove quote character before and after names when doing autocomplete
|
||||||
char* unquoted = strip_arg_quotes(input);
|
char* unquoted = strip_arg_quotes(input);
|
||||||
|
|
||||||
// MUC completion with nicknames
|
// MUC completion with nicknames
|
||||||
if (window->type == WIN_MUC) {
|
if (window->type == WIN_MUC) {
|
||||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
||||||
if (nick_ac) {
|
if (nick_ac) {
|
||||||
result = autocomplete_param_with_ac(unquoted, "/status get", nick_ac, TRUE, previous);
|
result = autocomplete_param_with_ac(unquoted, "/status get", nick_ac, TRUE, previous);
|
||||||
if (result) {
|
|
||||||
free(unquoted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// roster completion
|
|
||||||
} else {
|
|
||||||
result = _roster_jid_autocomplete(input, "/status get", previous);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
free(unquoted);
|
free(unquoted);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// roster completion
|
||||||
|
} else {
|
||||||
|
result = _roster_jid_autocomplete(input, "/status get", previous);
|
||||||
|
if (result) {
|
||||||
|
free(unquoted);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(unquoted);
|
free(unquoted);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -4230,14 +4232,12 @@ _software_autocomplete(ProfWin* window, const char* const input, gboolean previo
|
|||||||
{
|
{
|
||||||
char* result = NULL;
|
char* result = NULL;
|
||||||
|
|
||||||
if (window->type == WIN_CHAT) {
|
if (window->type == WIN_CHAT && _is_connected()) {
|
||||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||||
|
|
||||||
GString* search_str = g_string_new("/software ");
|
auto_gchar gchar* search_str = g_strdup_printf("/software %s", chatwin->barejid);
|
||||||
g_string_append(search_str, chatwin->barejid);
|
result = autocomplete_param_with_func(search_str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||||
result = autocomplete_param_with_func(search_str->str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
|
||||||
g_string_free(search_str, TRUE);
|
|
||||||
} else if (window->type == WIN_MUC) {
|
} else if (window->type == WIN_MUC) {
|
||||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
@@ -4350,10 +4350,10 @@ _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean pr
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = autocomplete_param_with_func(input, "/lastactivity set", prefs_autocomplete_boolean_choice, previous, NULL);
|
result = autocomplete_param_with_func(input, "/lastactivity set", prefs_autocomplete_boolean_choice, previous, NULL);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = _roster_jid_autocomplete(input, "/lastactivity get", previous);
|
result = _roster_jid_autocomplete(input, "/lastactivity get", previous);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user