From 7cd09e14cb3e9e7d694026fd5dbecc248f2e0a1b Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Tue, 24 May 2005 07:16:32 +0000 Subject: [PATCH] Improved handling of mal-formed binary messages --- mbuni/mmlib/mms_msg.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/mbuni/mmlib/mms_msg.c b/mbuni/mmlib/mms_msg.c index af6641b..f817b47 100644 --- a/mbuni/mmlib/mms_msg.c +++ b/mbuni/mmlib/mms_msg.c @@ -1027,11 +1027,9 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from) { int res = 0; MmsMsg _m = {0}, *m = NULL; - ParseContext *p = parse_context_create(msg); - + ParseContext *p = parse_context_create(msg); Octstr *s; - mms_strings_init(); /* Just in case. */ _m.headers = list_create(); @@ -1039,8 +1037,8 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from) if (_m.headers == NULL || list_len(_m.headers) == 0) - goto done; - + goto done; + /* Get the message type and also set flag for whether multipart.*/ s = http_header_value(_m.headers, octstr_imm("Content-Type")); @@ -1054,32 +1052,36 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from) if (s) { _m.message_type = mms_string_to_message_type(s); octstr_destroy(s); - } else { - if (_m.headers) http_destroy_headers(_m.headers); + } else goto done; - } + s = http_header_value(_m.headers, octstr_imm("Message-ID")); _m.msgId = s; - if ((res = decode_msgbody(p, &_m)) < 0) { - MmsMsg *msg = &_m; - if (msg->ismultipart && msg->body.l) - list_destroy(msg->body.l, (list_item_destructor_t *)mm_destroy); - else if (msg->body.s) - octstr_destroy(msg->body.s); - msg->ismultipart = 0; - msg->body.s = NULL; - } + if ((res = decode_msgbody(p, &_m)) < 0) /* A body decode error occured. */ + goto done; + - m = gw_malloc(sizeof (*m)); + m = gw_malloc(sizeof m[0]); /* all ok, copy. */ *m = _m; fixup_msg(m, from); - /* XXXX better error checking needed. */ done: parse_context_destroy(p); + if (!m) { /* This means an error occurred. Delete the interim stuff. */ + MmsMsg *msg = &_m; + + if (msg->ismultipart && msg->body.l) + list_destroy(msg->body.l, (list_item_destructor_t *)mm_destroy); + else if (msg->body.s) + octstr_destroy(msg->body.s); + if (msg->headers) + http_destroy_headers(msg->headers); + if (msg->msgId) + octstr_destroy(msg->msgId); + } return m; }