]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_pjsip: Ensure sanitized XML is NULL terminated. 39/1039/2
authorJoshua Colp <jcolp@digium.com>
Tue, 4 Aug 2015 21:12:59 +0000 (18:12 -0300)
committerJoshua Colp <jcolp@digium.com>
Thu, 6 Aug 2015 10:04:16 +0000 (07:04 -0300)
commit9e93ad109bb5445c300f3d5f85583a72fdc2b51d
treec4dc39e0fe8edc62b2ecefb975d5851e4841df53
parent4350fd22c8750028d21d998eff7c94e985a658b4
res_pjsip: Ensure sanitized XML is NULL terminated.

The ast_sip_sanitize_xml function is used to sanitize
a string for placement into XML. This is done by examining
an input string and then appending values to an output
buffer. The function used by its implementation, strncat,
has specific behavior that was not taken into account.
If the size of the input string exceeded the available
output buffer size it was possible for the sanitization
function to write past the output buffer itself causing
a crash. The crash would either occur because it was
writing into memory it shouldn't be or because the resulting
string was not NULL terminated.

This change keeps count of how much remaining space is
available in the output buffer for text and only allows
strncat to use that amount.

Since this was exposed by the res_pjsip_pidf_digium_body_supplement
module attempting to send a large message the maximum allowed
message size has also been increased in it.

A unit test has also been added which confirms that the
ast_sip_sanitize_xml function is providing NULL terminated
output even when the input length exceeds the output
buffer size.

ASTERISK-25304 #close

Change-Id: I743dd9809d3e13d722df1b0509dfe34621398302
res/res_pjsip.c
res/res_pjsip/presence_xml.c
res/res_pjsip_pidf_digium_body_supplement.c