I would rather change pkg_str_dup() and shm_str_dup()
to allocate len+1 and add the ending zero
That was my first approach. I just thought it would provoke more discussion (see below)
and I wanted to fix this bug fast, so I just kinda reverted the commits that introduced
it.
The problem with adding a zero on every copy is that a ```str``` is supposed to be useful
without a terminating zero. Lots of ```str``` uses are within the parser where ```str```
just points into the message buffer and has no terminating 0. Having them mixed will
inevitable lead to bugs (just like the one I'm trying to fix). All developers will
have to remember that only copies are 0-terminated.
Introducing a separate type for it (```strz```) will need duplicates for all existing str
functions as C doesn't allow type inheritance.
Another option is to create ```pkg_str_dupz()``` and ```shm_str_dupz()``` which will
0-terminate the copies.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2512#issuecomment-712661040