From f8028b5a94f1899ca1f20fa3f63d8949c91c7069 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Sat, 22 Feb 2014 23:01:41 +0100 Subject: [PATCH] OpenChange: Avoid crashing when creating embedded message in attachment Signed-off-by: Kamen Mazdrashki (cherry picked from commit 15a55f9f707247c9164e8fa7a102639744f686e5) --- OpenChange/MAPIStoreSOGo.m | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index 23cee8290..cd387cf32 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -61,6 +61,17 @@ sogo_backend_unexpected_error() return MAPISTORE_SUCCESS; } +static enum mapistore_error +sogo_backend_handle_objc_exception(NSException *e, const char *fn_name, const int line_no) +{ + DEBUG(0,("[SOGo: %s:%d] - EXCEPTION: %s, reason: %s\n", fn_name, line_no, [[e name] UTF8String], [[e reason] UTF8String])); + if ([[e name] isEqual:@"NotImplementedException"]) + { + return MAPISTORE_ERR_NOT_IMPLEMENTED; + } + return MAPISTORE_ERROR; +} + static void sogo_backend_atexit (void) { @@ -73,6 +84,7 @@ sogo_backend_atexit (void) GSUnregisterCurrentThread (); } + /** \details Initialize sogo mapistore backend @@ -1139,11 +1151,18 @@ sogo_message_attachment_create_embedded_message (void *attachment_object, attachment = wrapper->instance; GSRegisterCurrentThread (); pool = [NSAutoreleasePool new]; - rc = [attachment createEmbeddedMessage: &message - withMAPIStoreMsg: msg - inMemCtx: mem_ctx]; - if (rc == MAPISTORE_SUCCESS) - *message_object = [message tallocWrapper: mem_ctx]; + @try + { + rc = [attachment createEmbeddedMessage: &message + withMAPIStoreMsg: msg + inMemCtx: mem_ctx]; + if (rc == MAPISTORE_SUCCESS) + *message_object = [message tallocWrapper: mem_ctx]; + } + @catch (NSException *e) + { + rc = sogo_backend_handle_objc_exception(e, __FUNCTION__, __LINE__); + } [pool release]; GSUnregisterCurrentThread (); }