]> granicus.if.org Git - neomutt/commitdiff
Fix latest Coverity issues (#387)
authorPietro Cerutti <gahr@gahr.ch>
Fri, 10 Feb 2017 17:14:13 +0000 (17:14 +0000)
committerGitHub <noreply@github.com>
Fri, 10 Feb 2017 17:14:13 +0000 (17:14 +0000)
* Fix two use-before-check bugs

Closes #386

* Fix memory leak

Issue #386

* Treat a NULL b->subtype as a wildcard (*)

Issue #386

* Move assignment out of conditional

Closes #386

* Move assignment out of conditional (2)

Closes #386

imap/util.c
init.c
parse.c

index 35a472e5d87d04876bf9f5a1d37b1498390b3eb2..fa4c974ff767eb90f2e265449252603ab3616b6b 100644 (file)
@@ -909,15 +909,23 @@ int imap_wait_keepalive (pid_t pid)
 
 void imap_allow_reopen (CONTEXT *ctx)
 {
-  IMAP_DATA* idata = ctx->data;
-  if (ctx && ctx->magic == MUTT_IMAP && idata->ctx == ctx)
+  IMAP_DATA *idata;
+  if (!ctx || !ctx->data || ctx->magic != MUTT_IMAP)
+      return;
+
+  idata = ctx->data;
+  if (idata->ctx == ctx)
     idata->reopen |= IMAP_REOPEN_ALLOW;
 }
 
 void imap_disallow_reopen (CONTEXT *ctx)
 {
-  IMAP_DATA* idata = ctx->data;
-  if (ctx && ctx->magic == MUTT_IMAP && idata->ctx == ctx)
+  IMAP_DATA *idata;
+  if (!ctx || !ctx->data || ctx->magic != MUTT_IMAP)
+      return;
+
+  idata = ctx->data;
+  if (idata->ctx == ctx)
     idata->reopen &= ~IMAP_REOPEN_ALLOW;
 }
 
diff --git a/init.c b/init.c
index 26b292d909cdfbab8743c310583f2dab454eb316..8a5f9a898d6bc9ec9171693f3e709f4a2f65e6f4 100644 (file)
--- a/init.c
+++ b/init.c
@@ -506,11 +506,14 @@ static int add_to_replace_list (REPLACE_LIST **list, const char *pat, const char
   {
     t = mutt_new_replace_list();
     t->rx = rx;
+    rx = NULL;
     if (last)
       last->next = t;
     else
       *list = t;
   }
+  else
+    mutt_free_regexp(&rx);
 
   /* Now t is the REPLACE_LIST* that we want to modify. It is prepared. */
   t->template = safe_strdup(templ);
diff --git a/parse.c b/parse.c
index bf47b1fff04fc0a80c70246c7072290104580f94..da006af9d090e3ed22cde8f8f531549c2f9c0afe 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1565,9 +1565,10 @@ static int count_body_parts_check(LIST **checklist, BODY *b, int dflt)
     a = (ATTACH_MATCH *)type->data;
     mutt_debug (5, "cbpc: %s %d/%s ?? %s/%s [%d]... ",
                 dflt ? "[OK]   " : "[EXCL] ",
-                b->type, b->subtype, a->major, a->minor, a->major_int);
+                b->type, b->subtype ? b->subtype : "*",
+                a->major, a->minor, a->major_int);
     if ((a->major_int == TYPEANY || a->major_int == b->type) &&
-       !regexec(&a->minor_rx, b->subtype, 0, NULL, 0))
+        (!b->subtype || !regexec(&a->minor_rx, b->subtype, 0, NULL, 0)))
     {
       mutt_debug (5, "yes\n");
       return 1;