res_pjsip: Ensure sanitized XML is NULL terminated.
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:20:47 +0000 (05:20 -0500)
commit4b6c657a820334ed3bef9daee48f21d6a9659f98
tree217f64e86aee7eb0a798c18ecbf94956f90ff6c1
parent3d4db97253a059d38d3e37b34c44ee02448fbab9
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