db_updater: Allocate space for trailing NULL byte for long output
commit8b706031c3a92e0753d0c0af4eac5a99cf3476ca
authorRobin Sonefors <robin.sonefors@op5.com>
Wed, 9 Jul 2014 07:54:24 +0000 (9 09:54 +0200)
committerRobin Sonefors <robin.sonefors@op5.com>
Wed, 9 Jul 2014 12:07:22 +0000 (9 14:07 +0200)
treeed6df8024fef0965a56751091b564c3492249c97
parent4090b2a15e1fefe426fd6afc7f75356ea5bcda88
db_updater: Allocate space for trailing NULL byte for long output

When we unescaped strings without newlines, we always wrote a trailing
NULL byte, without actually allocating space for it. This lead to
frequent merlin crashes.

The problem is that unescape_newline is not quite sure if the length
bounds the input or the output - it mostly assumes it bounds both, but
"mostly" is a bad word in C programming.

This fix makes unescape_newline treat its data completely like escaped
binary data - it is now the users job to make sure NULL bytes are where
they're expected. In db_updater, we know that they're in place (as we
dared relying on a strlen), so we can just include this byte among the
bytes we copy.

Change-Id: I6d582103e72b2b3bc937ad1badf8ca52248c5b8b
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
db_updater.c
string_utils.c
string_utils.h
test-stringutils.c