]> granicus.if.org Git - neomutt/commitdiff
coverity: fix defects
authorRichard Russon <rich@flatcap.org>
Thu, 11 May 2017 14:28:34 +0000 (15:28 +0100)
committerRichard Russon <rich@flatcap.org>
Fri, 12 May 2017 14:27:15 +0000 (15:27 +0100)
Most of these trivial problems were discovered when NNTP got enabled in
the default build.

- dereference after null check
- resource leak
- uninit pointer
- uninit var
- unused value

account.c
browser.c
init.c
keymap.c
newsrc.c
nntp.c
send.c
sendlib.c

index ce5402da9d754d3c8958cd4956e160f982878c96..121e2c2dc28e2c2ab127db023f3253335f9b2474 100644 (file)
--- a/account.c
+++ b/account.c
@@ -104,6 +104,7 @@ void mutt_account_tourl(ACCOUNT *account, ciss_url_t *url)
   url->user = NULL;
   url->pass = NULL;
   url->port = 0;
+  url->path = NULL;
 
 #ifdef USE_IMAP
   if (account->type == MUTT_ACCT_TYPE_IMAP)
index a91a0e75e67917926e5815f2dfc6d7f1d60aeeb6..2a7a7420170235e6e611621383ca5e8cd79fb433 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -1934,7 +1934,6 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf
         if (option(OPTNEWS))
         {
           NNTP_SERVER *nserv = CurrentNewsSrv;
-          NNTP_DATA *nntp_data = NULL;
           regex_t *rx = safe_malloc(sizeof(regex_t));
           char *s = buf;
           int rc, j = menu->current;
@@ -1985,9 +1984,9 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf
                 regexec(rx, ff->name, 0, NULL, 0) == 0)
             {
               if (i == OP_BROWSER_SUBSCRIBE || i == OP_SUBSCRIBE_PATTERN)
-                nntp_data = mutt_newsgroup_subscribe(nserv, ff->name);
+                mutt_newsgroup_subscribe(nserv, ff->name);
               else
-                nntp_data = mutt_newsgroup_unsubscribe(nserv, ff->name);
+                mutt_newsgroup_unsubscribe(nserv, ff->name);
             }
             if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE)
             {
@@ -2003,7 +2002,7 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf
 
             for (k = 0; nserv && k < nserv->groups_num; k++)
             {
-              nntp_data = nserv->groups_list[k];
+              NNTP_DATA *nntp_data = nserv->groups_list[k];
               if (nntp_data && nntp_data->group && !nntp_data->subscribed)
               {
                 if (regexec(rx, nntp_data->group, 0, NULL, 0) == 0)
diff --git a/init.c b/init.c
index 024f4e6abf7d7177750c7459d7371bcc8c923b29..1c14825701f442ac003f54f2c55a0f013d0efbe5 100644 (file)
--- a/init.c
+++ b/init.c
@@ -4026,7 +4026,10 @@ void mutt_init(int skip_sys_rc, LIST *commands)
     }
   }
   if ((p = getenv("NNTPSERVER")))
+  {
+    FREE(&NewsServer);
     NewsServer = safe_strdup(p);
+  }
 #endif
 
   if ((p = getenv("MAIL")))
index 663d44f9580a33ed08e60ea2eec74c525d8746a8..15e4667d18a6af0f33e270647bdaf5be1a9de0f2 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -1094,8 +1094,7 @@ int mutt_parse_bind(BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
       }
 
       /* Clear any error message, we're going to try again */
-      if (err->data)
-        err->data[0] = '\0';
+      err->data[0] = '\0';
       bindings = km_get_table(menu[i]);
       if (bindings)
       {
index 81dcf60a00e8594018180fe99c0f32a3aa012f7b..e89a1e2821777d39fc1227ccb4a8b86b7be4f68d 100644 (file)
--- a/newsrc.c
+++ b/newsrc.c
@@ -1198,7 +1198,11 @@ NNTP_DATA *mutt_newsgroup_uncatchup(NNTP_SERVER *nserv, char *group)
       mutt_set_flag(Context, Context->hdrs[i], MUTT_READ, 0);
   }
   else
-    nntp_data->unread = nntp_data->lastMessage - nntp_data->newsrc_ent[0].last;
+  {
+    nntp_data->unread = nntp_data->lastMessage;
+    if (nntp_data->newsrc_ent)
+      nntp_data->unread -= nntp_data->newsrc_ent[0].last;
+  }
   return nntp_data;
 }
 
diff --git a/nntp.c b/nntp.c
index f663595ea7f25b3abed9d23be414abbc705911f4..b5ca8dde5314f8157842d8fe5437256efcc42c1a 100644 (file)
--- a/nntp.c
+++ b/nntp.c
@@ -1676,10 +1676,14 @@ int nntp_post(const char *msg)
 
   strfcpy(buf, "POST\r\n", sizeof(buf));
   if (nntp_query(nntp_data, buf, sizeof(buf)) < 0)
+  {
+    safe_fclose(&fp);
     return -1;
+  }
   if (buf[0] != '3')
   {
     mutt_error(_("Can't post article: %s"), buf);
+    safe_fclose(&fp);
     return -1;
   }
 
@@ -2056,6 +2060,7 @@ static int nntp_date(NNTP_SERVER *nserv, time_t *now)
     NNTP_DATA nntp_data;
     char buf[LONG_STRING];
     struct tm tm;
+    memset(&tm, 0, sizeof(tm));
 
     nntp_data.nserv = nserv;
     nntp_data.group = NULL;
diff --git a/send.c b/send.c
index ab92750080a9d72b611e6e291f0bf1ce4d836b7b..a62cde2fd30219fd9010f6578d32a10804a861d3 100644 (file)
--- a/send.c
+++ b/send.c
@@ -655,6 +655,9 @@ void mutt_fix_reply_recipients(ENVELOPE *env)
 
 void mutt_make_forward_subject(ENVELOPE *env, CONTEXT *ctx, HEADER *cur)
 {
+  if (!env)
+    return;
+
   char buffer[STRING];
 
   /* set the default subject for the message. */
@@ -664,6 +667,9 @@ void mutt_make_forward_subject(ENVELOPE *env, CONTEXT *ctx, HEADER *cur)
 
 void mutt_make_misc_reply_headers(ENVELOPE *env, CONTEXT *ctx, HEADER *cur, ENVELOPE *curenv)
 {
+  if (!env || !curenv)
+    return;
+
   /* This takes precedence over a subject that might have
    * been taken from a List-Post header.  Is that correct?
    */
@@ -717,6 +723,9 @@ void mutt_add_to_reference_headers(ENVELOPE *env, ENVELOPE *curenv, LIST ***pp,
 
 static void make_reference_headers(ENVELOPE *curenv, ENVELOPE *env, CONTEXT *ctx)
 {
+  if (!env || !ctx)
+    return;
+
   env->references = NULL;
   env->in_reply_to = NULL;
 
@@ -771,14 +780,16 @@ static int envelope_defaults(ENVELOPE *env, CONTEXT *ctx, HEADER *cur, int flags
   else
     curenv = cur->env;
 
+  if (!curenv)
+    return -1;
+
   if (flags & SENDREPLY)
   {
 #ifdef USE_NNTP
     if ((flags & SENDNEWS))
     {
       /* in case followup set Newsgroups: with Followup-To: if it present */
-      if (!env->newsgroups && curenv &&
-          (mutt_strcasecmp(curenv->followup_to, "poster") != 0))
+      if (!env->newsgroups && (mutt_strcasecmp(curenv->followup_to, "poster") != 0))
         env->newsgroups = safe_strdup(curenv->followup_to);
     }
     else
index f18f6956cceddfaf5fb3001773f36c8d2b778bd6..fd0657d12b165f8daa6690efe1431d585f1cde00 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2354,7 +2354,7 @@ int mutt_invoke_sendmail(ADDRESS *from, /* the sender */
                          const char *msg, /* file containing message */
                          int eightbit)    /* message contains 8bit chars */
 {
-  char *ps = NULL, *path = NULL, *s = safe_strdup(Sendmail), *childout = NULL;
+  char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
   char **args = NULL;
   size_t argslen = 0, argsmax = 0;
   char **extra_args = NULL;
@@ -2377,7 +2377,9 @@ int mutt_invoke_sendmail(ADDRESS *from, /* the sender */
 
     s = safe_strdup(cmd);
   }
+  else
 #endif
+    s = safe_strdup(Sendmail);
 
   /* ensure that $sendmail is set to avoid a crash. http://dev.mutt.org/trac/ticket/3548 */
   if (!s)