Issue 4180 heap use after free cloned hdr#4182
Conversation
|
This failed the CI tests |
pjsip/src/pjsip/sip_msg.c
Outdated
| { | ||
| pjsip_generic_int_hdr *hdr = PJ_POOL_ALLOC_T(pool, pjsip_generic_int_hdr); | ||
| pj_memcpy(hdr, rhs, sizeof(*hdr)); | ||
| pjsip_generic_int_hdr *hdr = pjsip_generic_int_hdr_create(pool, &rhs->name, rhs->ivalue); |
There was a problem hiding this comment.
Just realized that it is a generic header, using pjsip_generic_int_hdr_create() will always reset the header type to PJSIP_H_OTHER. So from the original code, only adding header name duplication (especially if the type is PJSIP_H_OTHER) is sufficient?
There was a problem hiding this comment.
Hello,
pjsip_generic_int_hdr_create() calls pjsip_generic_int_hdr_init() which will allocate new space in the provided pj_pool_t for the header name of the cloned header via pj_strdup() (pjsip/src/pjsip/sip_msg.c:863), this is what we need.
Otherwise, the header name of the cloned header points to a memory space of the source header pj_pool_t.
I think this is sufficient for the error detected by ASAN.
There was a problem hiding this comment.
Hi,
As mentioned before, the problem with the patch is that pjsip_generic_array_hdr_create()/pjsip_generic_int_hdr_create() will reset the header type to PJSIP_H_OTHER. Note that the cloned header can be pjsip_expires_hdr which is derived from pjsip_generic_int_hdr and has header type of PJSIP_H_EXPIRES.
So if the missing part is only pj_strdup() for the header name (especially for PJSIP_H_OTHER), why not just add only it, instead of replacing the whole thing with pjsip_generic_*_hdr_create() (which may reset things such as header type).
pjsip/src/pjsip/sip_msg.c
Outdated
| { | ||
| unsigned i; | ||
| pjsip_generic_array_hdr *hdr = PJ_POOL_ALLOC_T(pool, pjsip_generic_array_hdr); | ||
| pjsip_generic_array_hdr *hdr = pjsip_generic_array_hdr_create(pool, &rhs->name); |
There was a problem hiding this comment.
pjsip_generic_array_hdr_create() does the same by calling pjsip_generic_array_hdr_init() which allocate new space in the provided pj_pool_t for the header name of the cloned header via pj_strdup() (pjsip/src/pjsip/sip_msg.c:939).
The problem doesn't exist with header which are not PJSIP_H_OTHER because the header name points to a static memory space defined by const pjsip_hdr_name_info_t pjsip_hdr_names[];.
|
Alright, I didn't get your point, now it's clear, you are right. |
You're right.
You're right again. Just perhaps creating Also, just a minor, it is better to maintain the column width limit <= 80. |
Use pjsip_generic_int_hdr_create() to allocate space for header name on the provided pool.
3951f8f to
e2494c0
Compare
|
Alright, I have removed |
Use pjsip_generic_array_hdr_create() to allocate space for header name on the provided pool.
e2494c0 to
72b8c33
Compare
|
|
This pull request should fix the issue 4180