]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_pjsip: Ensure sanitized XML is NULL terminated. 38/1038/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:03:28 +0000 (07:03 -0300)
commit8521a86367ac6090210a89878c8fee6d19c43642
tree5df9b42411b71b2226c260ac2b73f0ad119a59ab
parentc07fa843ec49a114473fe3b5609d00f80ace1b3d
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