]> granicus.if.org Git - neomutt/commitdiff
notmuch: fix crash when completing tags (#395)
authorWilliam Pettersson <william.pettersson+github@gmail.com>
Tue, 14 Feb 2017 18:24:02 +0000 (05:24 +1100)
committerRichard Russon <rich@flatcap.org>
Tue, 14 Feb 2017 18:24:02 +0000 (18:24 +0000)
Notmuch was found to sometimes return a NULL when asked for a list of
tags.  This caused mutt to crash when trying to autocomplete.

Thanks to William Pettersson (@WPettersson) for the initial patch.

Closes #393
Closes #395

init.c
mutt_notmuch.c

diff --git a/init.c b/init.c
index 5bf71027cdbd4d82510880eaa7efdf82fc04a7a9..086a051385960a1b5de07a380f958affbc68a73c 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2971,6 +2971,9 @@ static void matches_ensure_morespace(int current)
 */
 static void candidate (char *dest, char *try, const char *src, int len)
 {
+  if (!dest || !try || !src)
+    return;
+
   int l;
 
   if (strstr (src, try) == src)
index ba252da885e4fb92e23add19baccbaadb2c24e9e..a204892bea4b6ac8dc3e41e329f76a9c644f8dfe 100644 (file)
@@ -2109,6 +2109,7 @@ int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count)
   struct nm_ctxdata *data = get_ctxdata(ctx);
   notmuch_database_t *db = NULL;
   notmuch_tags_t *tags = NULL;
+  const char *tag;
   int rc = -1;
 
   if (!data)
@@ -2123,11 +2124,14 @@ int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count)
 
   while (notmuch_tags_valid(tags))
   {
-    if (tag_list != NULL)
+    tag = notmuch_tags_get(tags);
+    /* Skip empty string */
+    if (*tag)
     {
-      tag_list[*tag_count] = safe_strdup(notmuch_tags_get(tags));
+      if (tag_list != NULL)
+        tag_list[*tag_count] = safe_strdup(tag);
+      (*tag_count)++;
     }
-    (*tag_count)++;
     notmuch_tags_move_to_next(tags);
   }