diff --git a/channels/chan_sip.c b/channels/chan_sip.c index fc176db02210d68b366f173f23e703878f5a51ea..e7e0e9282be0440547ea9a270d2cf9561aaf2127 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -8305,18 +8305,24 @@ static void copy_request(struct sip_request *dst, const struct sip_request *src) memcpy(dst, src, sizeof(*dst)); dst->data = dup; - if (!dst->data && !(dst->data = ast_str_create(src->data->used))) + /* All these + 1's are to account for the need to include the NULL terminator + * Using typical string functions like ast_copy_string or ast_str_set will not + * work in this case because the src's data string is riddled with \0's all over + * the place and so a memcpy is the only way to accurately copy the string + */ + + if (!dst->data && !(dst->data = ast_str_create(src->data->used + 1))) return; else if (dst->data->len < src->data->used) - ast_str_make_space(&dst->data, src->data->used); + ast_str_make_space(&dst->data, src->data->used + 1); - memcpy(dst->data->str, src->data->str, src->data->used); + memcpy(dst->data->str, src->data->str, src->data->used + 1); dst->data->used = src->data->used; offset = ((void *)dst->data->str) - ((void *)src->data->str); /* Now fix pointer arithmetic */ - for (x=0; x < src->headers; x++) + for (x = 0; x < src->headers; x++) dst->header[x] += offset; - for (x=0; x < src->lines; x++) + for (x = 0; x < src->lines; x++) dst->line[x] += offset; /* On some occasions this function is called without parse_request being called first so lets not create an invalid pointer */ if (src->rlPart1)