Add some safeguards against NULL base msg
authorAndre Heinecke <aheinecke@intevation.de>
Thu, 6 Sep 2018 15:19:07 +0000 (17:19 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Thu, 6 Sep 2018 15:19:07 +0000 (17:19 +0200)
* src/common.h (ERR_GET_BASE_MSG_FAILED): Add new bug code.
* src/mailitem-events.cpp (Send): Check for null base msg
* src/windowmessages.cpp (gpgol_window_proc): ditto.
* src/ribbon-callbacks.cpp (get_mail_from_control): ditto.

--
Except for get_mail_from_control this should never be hit
(thus the bug error) but accessing a pointer before checking
it seemed wrong.

src/common.h
src/mailitem-events.cpp
src/ribbon-callbacks.cpp
src/windowmessages.cpp

index 583a63a..0ed0d11 100644 (file)
@@ -124,6 +124,7 @@ void i18n_init (void);
 #define ERR_INLINE_BODY_TO_BODY 4
 #define ERR_INLINE_BODY_INV_STATE 5
 #define ERR_SEND_FALLBACK_FAILED 6
+#define ERR_GET_BASE_MSG_FAILED 7
 #ifdef __cplusplus
 }
 #endif
index 26cbbdd..1653565 100644 (file)
@@ -518,17 +518,23 @@ EVENT_SINK_INVOKE(MailItemEvents)
                   log_debug ("%s:%s: Message %p - Activating T3656 Workaround",
                              SRCNAME, __func__, m_object);
                   message = get_oom_base_message (m_object);
-                  // It's important we use the _base_ message here.
-                  mapi_save_changes (message, KEEP_OPEN_READWRITE | FORCE_SAVE);
-                  message->SubmitMessage(0);
-                  gpgol_release (message);
-
+                  if (message)
+                    {
+                      // It's important we use the _base_ message here.
+                      mapi_save_changes (message, FORCE_SAVE);
+                      message->SubmitMessage(0);
+                      gpgol_release (message);
+                      // Close the composer and trigger unloads
+                      CloseHandle(CreateThread (NULL, 0, close_mail, (LPVOID) m_mail, 0,
+                                                NULL));
+                    }
+                  else
+                    {
+                      gpgol_bug (nullptr,
+                                 ERR_GET_BASE_MSG_FAILED);
+                    }
                   // Cancel send
                   *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
-
-                  // Close the composer and trigger unloads
-                  CloseHandle(CreateThread (NULL, 0, close_mail, (LPVOID) m_mail, 0,
-                                            NULL));
                 }
               MAPIFreeBuffer (propval);
               if (*(parms->rgvarg[0].pboolVal) == VARIANT_TRUE)
index e9f8a5e..d7ea3c4 100644 (file)
@@ -531,6 +531,13 @@ get_mail_from_control (LPDISPATCH ctrl, bool *none_selected)
   if (!uid)
     {
       LPMESSAGE msg = get_oom_base_message (mailitem);
+      if (!msg)
+        {
+          log_debug ("%s:%s: Failed to get message for %p",
+                   SRCNAME, __func__, mailitem);
+          gpgol_release (mailitem);
+          return NULL;
+        }
       uid = mapi_get_uid (msg);
       gpgol_release (msg);
       if (!uid)
index ff8a1db..25c5dcd 100644 (file)
@@ -169,9 +169,14 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                              "Trying SubmitMessage instead.",
                              SRCNAME, __func__, mail);
                   auto mail_message = get_oom_base_message (mail->item());
+                  if (!mail_message)
+                    {
+                      gpgol_bug (mail->getWindow (),
+                                 ERR_GET_BASE_MSG_FAILED);
+                      break;
+                    }
                   // It's important we use the _base_ message here.
-                  mapi_save_changes (mail_message,
-                                     KEEP_OPEN_READWRITE | FORCE_SAVE);
+                  mapi_save_changes (mail_message, FORCE_SAVE);
                   HRESULT hr = mail_message->SubmitMessage(0);
                   gpgol_release (mail_message);