-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
textops: get_body_part doesn't detect multipart headers ending properly #564
Comments
I have no example of a multipart body in my pile of cool INVITE messages. Would it be possible for /O
|
Hi, Here is one example, the XML body is not standard (yet), so I had to remove it. Content-Length is to be checked
The command get_body_part("application/sdp", "$var(sdp)"); writes the following content in $var(sdp):
But the expected content is:
"Content-Length: 479" is a multipart header and should be ignored. From what I understand everything after a "Content-Type:" is considered as a body. |
I finally had some time to look into the source code, the issue comes from the file textops/textops.c:2071 while (find_line_start("Content-Type: ", 14, &start, &len))
{
end = start + 14;
len = len - 14;
if (len > (content_type.len + 2)) {
if (strncasecmp(end, content_type.s, content_type.len)== 0)
{
LM_DBG("found content type %.*s\n",
content_type.len, content_type.s);
end = end + content_type.len;
if ((*end != 13) || (*(end + 1) != 10))
{
LM_ERR("no CRLF found after content type\n");
goto err;
}
end = end + 2;
len = len - content_type.len - 2;
body_headers_end = end;
if (find_line_start(boundary.s, boundary.len, &end,
&len))
{ Thanks to the pull "textops: Fix get_body_part() end of body headers #423" by smititelu, textops is now able to find the end of multipart headers in the simple case of just a "Content-type" header. But it is not able to handle more complex cases like this one for instance (from RFC 5621 https://tools.ietf.org/html/rfc5621#section-3.1):
Here "Content-Disposition: recipient-list" would be taken into the second body because the variable body_headers_end would be set just after the content type header by find_line_start("Content-Type: ", 14, &start, &len). I think that maybe something like: body_headers_end = find_line_start("\r\n", 14, &start, &len); Instead of: body_headers_end = end; Might help. Because a \r\n should always separate headers from the body as it is specified for instance in RFC 3261 (https://tools.ietf.org/html/rfc3261#section-7) for SIP headers:
I will test this solution as soon as I will have more spare time. |
Thanks for troubleshooting further. If you test your solution and works ok, make a pull request with the patch, to be reviewed and eventually merged. |
@foucse can you try this changes? |
If still an issue, reopen, the patch referenced above is more than 5 months old. |
When I use get_body_part on a multipart body, it doesn't detect properly the ending of multipart headers:
For instance in:
"Content-Length: 479" is taken into get_body_part("application/sdp", "$var(sdp)");
I will try to provide more details later.
The text was updated successfully, but these errors were encountered: