Improved handling of mal-formed binary messages
This commit is contained in:
parent
e3b7753a27
commit
7cd09e14cb
|
@ -1027,11 +1027,9 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
MmsMsg _m = {0}, *m = NULL;
|
MmsMsg _m = {0}, *m = NULL;
|
||||||
ParseContext *p = parse_context_create(msg);
|
ParseContext *p = parse_context_create(msg);
|
||||||
|
|
||||||
Octstr *s;
|
Octstr *s;
|
||||||
|
|
||||||
|
|
||||||
mms_strings_init(); /* Just in case. */
|
mms_strings_init(); /* Just in case. */
|
||||||
|
|
||||||
_m.headers = list_create();
|
_m.headers = list_create();
|
||||||
|
@ -1039,8 +1037,8 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from)
|
||||||
|
|
||||||
if (_m.headers == NULL ||
|
if (_m.headers == NULL ||
|
||||||
list_len(_m.headers) == 0)
|
list_len(_m.headers) == 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Get the message type and also set flag for whether multipart.*/
|
/* Get the message type and also set flag for whether multipart.*/
|
||||||
|
|
||||||
s = http_header_value(_m.headers, octstr_imm("Content-Type"));
|
s = http_header_value(_m.headers, octstr_imm("Content-Type"));
|
||||||
|
@ -1054,32 +1052,36 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from)
|
||||||
if (s) {
|
if (s) {
|
||||||
_m.message_type = mms_string_to_message_type(s);
|
_m.message_type = mms_string_to_message_type(s);
|
||||||
octstr_destroy(s);
|
octstr_destroy(s);
|
||||||
} else {
|
} else
|
||||||
if (_m.headers) http_destroy_headers(_m.headers);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
s = http_header_value(_m.headers, octstr_imm("Message-ID"));
|
s = http_header_value(_m.headers, octstr_imm("Message-ID"));
|
||||||
_m.msgId = s;
|
_m.msgId = s;
|
||||||
|
|
||||||
if ((res = decode_msgbody(p, &_m)) < 0) {
|
if ((res = decode_msgbody(p, &_m)) < 0) /* A body decode error occured. */
|
||||||
MmsMsg *msg = &_m;
|
goto done;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
m = gw_malloc(sizeof (*m));
|
m = gw_malloc(sizeof m[0]); /* all ok, copy. */
|
||||||
*m = _m;
|
*m = _m;
|
||||||
|
|
||||||
fixup_msg(m, from);
|
fixup_msg(m, from);
|
||||||
|
|
||||||
/* XXXX better error checking needed. */
|
|
||||||
done:
|
done:
|
||||||
parse_context_destroy(p);
|
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;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue