mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-02 02:18:31 +00:00
res_pjsip_pubsub.c: Fix one byte buffer overrun error.
ast_sip_pubsub_register_body_generator() did not account for the null terminator set by sprintf() in the allocated output buffer. Change-Id: I388688a132e479bca6ad1c19275eae0070969ae2
This commit is contained in:
@@ -2995,16 +2995,13 @@ int ast_sip_pubsub_register_body_generator(struct ast_sip_pubsub_body_generator
|
|||||||
AST_LIST_INSERT_HEAD(&body_generators, generator, list);
|
AST_LIST_INSERT_HEAD(&body_generators, generator, list);
|
||||||
AST_RWLIST_UNLOCK(&body_generators);
|
AST_RWLIST_UNLOCK(&body_generators);
|
||||||
|
|
||||||
/* Lengths of type and subtype plus space for a slash. pj_str_t is not
|
/* Lengths of type and subtype plus a slash. */
|
||||||
* null-terminated, so there is no need to allocate for the extra null
|
|
||||||
* byte
|
|
||||||
*/
|
|
||||||
accept_len = strlen(generator->type) + strlen(generator->subtype) + 1;
|
accept_len = strlen(generator->type) + strlen(generator->subtype) + 1;
|
||||||
|
|
||||||
accept.ptr = ast_alloca(accept_len);
|
/* Add room for null terminator that sprintf() will set. */
|
||||||
accept.slen = accept_len;
|
pj_strset(&accept, ast_alloca(accept_len + 1), accept_len);
|
||||||
/* Safe use of sprintf */
|
sprintf((char *) pj_strbuf(&accept), "%s/%s", generator->type, generator->subtype);/* Safe */
|
||||||
sprintf(accept.ptr, "%s/%s", generator->type, generator->subtype);
|
|
||||||
pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), &pubsub_module,
|
pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), &pubsub_module,
|
||||||
PJSIP_H_ACCEPT, NULL, 1, &accept);
|
PJSIP_H_ACCEPT, NULL, 1, &accept);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user