[balsa/wip/gmime3: 52/197] Assert that an ImapMboxHandle is not NULL



commit f0c3e5782cd70293e4914c4e44c8a54c6b927a72
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Aug 11 22:38:28 2017 -0400

    Assert that an ImapMboxHandle is not NULL
    
        * libbalsa/imap/imap-handle.c (idle_start): assert that the
          handle is not NULL, to avoid the appearance of dereferencing a
          NULL pointer.

 ChangeLog                   |    6 ++++++
 libbalsa/imap/imap-handle.c |   14 ++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 53838f6..b41f476 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-08-11  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       * libbalsa/imap/imap-handle.c (idle_start): assert that the
+         handle is not NULL, to avoid the appearance of dereferencing a
+         NULL pointer.
+
 2017-08-10  Albrecht Dreß
 
        Crypto-related (mostly) fixes and improvements
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 9587a1b..abbc907 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -436,12 +436,19 @@ idle_start(gpointer data)
   ImapCmdTag tag;
   unsigned asyncno;
 
-  /* The test below can probably be weaker since it is ok for the
-     channel to get disconnected before IDLE gets activated */
+  g_assert(h != NULL);
+
   if(!g_mutex_trylock(&h->mutex))
     return TRUE;/* Don't block, just try again later. */
+
+  /* One way or another, we are now going to return FALSE,
+   * so clear the idle id: */
+  h->idle_enable_id = 0;
+
+  /* The test below can probably be weaker since it is ok for the
+     channel to get disconnected before IDLE gets activated */
   IMAP_REQUIRED_STATE3(h, IMHS_CONNECTED, IMHS_AUTHENTICATED,
-                       IMHS_SELECTED, (h->idle_enable_id = 0, FALSE));
+                       IMHS_SELECTED, FALSE);
 
   asyncno = imap_make_tag(tag); sio_write(h->sio, tag, strlen(tag));
   sio_write(h->sio, " IDLE\r\n", 7); sio_flush(h->sio);
@@ -453,7 +460,6 @@ idle_start(gpointer data)
   if(ASYNC_DEBUG) printf("async_process() registered\n");
   h->async_watch_id = g_io_add_watch(h->iochannel, G_IO_IN|G_IO_HUP,
                                     async_process, h);
-  h->idle_enable_id = 0;
   h->idle_state = IDLE_RESPONSE_PENDING;
 
   g_mutex_unlock(&h->mutex);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]