1
0
Fork 0

Improved handling of mal-formed binary messages

This commit is contained in:
bagyenda 2005-05-24 07:16:32 +00:00
parent e3b7753a27
commit 7cd09e14cb
1 changed files with 21 additions and 19 deletions

View File

@ -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;
}