summaryrefslogtreecommitdiff
path: root/res/res_pjsip_xpidf_body_generator.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-07-02 14:51:29 -0500
committerRichard Mudgett <rmudgett@digium.com>2015-07-06 16:15:12 -0500
commit7cd99be534945fffd5927554c9c4469454008d3c (patch)
treedd067111bae6b7adae9d8cbddb48b96664522600 /res/res_pjsip_xpidf_body_generator.c
parent792ed7ce93205fc700b3923640fa023b34eff5cb (diff)
PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error.
When res_pjsip body generator modules were generating XML or XPIDF response bodies, there was a chance that the generated body would be the exact size of the supplied buffer. Adding the nul string terminator would then write beyond the end of the buffer and potentially corrupt memory. * Fix MALLOC_DEBUG high fence violations caused by adding a nul string terminator on the end of a buffer for XML or XPIDF response bodies. * Made calls to pj_xml_print() safer if the XML prolog is requested. Due to a bug in pjproject, the return value could be -1 _or_ AST_PJSIP_XML_PROLOG_LEN if the supplied buffer is not large enough. * Updated the doxygen comment of AST_PJSIP_XML_PROLOG_LEN to describe the return value of pj_xml_print() when the supplied buffer is not large enough. ASTERISK-25168 Reported by: Carl Fortin Change-Id: Id70e1d373a6a2b2bd9e678b5cbc5e55b308981de
Diffstat (limited to 'res/res_pjsip_xpidf_body_generator.c')
-rw-r--r--res/res_pjsip_xpidf_body_generator.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/res/res_pjsip_xpidf_body_generator.c b/res/res_pjsip_xpidf_body_generator.c
index 37676ff96..924046549 100644
--- a/res/res_pjsip_xpidf_body_generator.c
+++ b/res/res_pjsip_xpidf_body_generator.c
@@ -106,14 +106,13 @@ static void xpidf_to_string(void *body, struct ast_str **str)
int size;
do {
- size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str));
- if (size == AST_PJSIP_XML_PROLOG_LEN) {
+ size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
+ if (size <= AST_PJSIP_XML_PROLOG_LEN) {
ast_str_make_space(str, ast_str_size(*str) * 2);
++growths;
}
- } while (size == AST_PJSIP_XML_PROLOG_LEN && growths < MAX_STRING_GROWTHS);
-
- if (size == AST_PJSIP_XML_PROLOG_LEN) {
+ } while (size <= AST_PJSIP_XML_PROLOG_LEN && growths < MAX_STRING_GROWTHS);
+ if (size <= AST_PJSIP_XML_PROLOG_LEN) {
ast_log(LOG_WARNING, "XPIDF body text too large\n");
return;
}