[sr-dev] [kamailio] core: NULL checks for ut.h (#401)

Stefan Mititelu notifications at github.com
Thu Nov 19 09:06:57 CET 2015


Considering the following _fallback case_ :
- alloc dst->s = pointer sizeof(void\*)
- dst->len = 0
- return **0**

After skimming the code a little more I came to this for the above case(i.e. src->s is NULL):
- either make dst->s = NULL; dst->len = 0 and return **-1**; this will be caught by shm_str_dup() != 0 and prevent shm_free() a NULL pointer, even though memory managers checks for this and gives L_WARN
- or keep the fallback case; further uses of the dst should be done based on the dst->len (i.e. cmp_str() or LM_ERR("%.*s"))

I'd go for the second option. What do you think?

Also I've seen that the memory manager allocate and 'unsigned int'. So, if shm/pkg_str_dup() is called with src->len < 0 it will probably fail (depending on the negative value). In this case, I'd also force the fallback case.

---
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/401#issuecomment-157984715
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20151119/aec5b103/attachment.html>


More information about the sr-dev mailing list