From 1d1189aeab499eb27faafa694e610c4e7cc9cc86 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 14 Sep 2016 14:30:19 +0200 Subject: [PATCH] Fix crash if completing with NULL shell_cur This happens if you do e.g. flatpak complete "flatpak install " 11 Reported by aki237 --- common/flatpak-utils.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index 306c6e86..ae0a0a6a 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -3716,6 +3716,7 @@ flatpak_complete_word (FlatpakCompletion *completion, { va_list args; const char *rest; + const char *shell_cur; g_autofree char *string = NULL; g_return_if_fail (format != NULL); @@ -3727,11 +3728,13 @@ flatpak_complete_word (FlatpakCompletion *completion, if (!g_str_has_prefix (string, completion->cur)) return; + shell_cur = completion->shell_cur ? completion->shell_cur : ""; + /* I'm not sure exactly what bash is doing here, but this seems to work... */ - if (strcmp (completion->shell_cur, "=") == 0) - rest = string + strlen (completion->cur) - strlen (completion->shell_cur) + 1; + if (strcmp (shell_cur, "=") == 0) + rest = string + strlen (completion->cur) - strlen (shell_cur) + 1; else - rest = string + strlen (completion->cur) - strlen (completion->shell_cur); + rest = string + strlen (completion->cur) - strlen (shell_cur); flatpak_completion_debug ("completing word: '%s' (%s)", string, rest);