Avoid serializing NULL string through msgpack

Attempting to serialize a NULL string through msgpack results in
msgpack_sbuffer_write attempting to memcpy from a NULL pointer, which is
undefined behavior.
This commit is contained in:
James McCoy 2016-11-17 18:16:46 -05:00
parent 38ee85d000
commit ca292c9768
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
2 changed files with 6 additions and 2 deletions

View File

@ -326,7 +326,9 @@ void msgpack_rpc_from_string(String result, msgpack_packer *res)
FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_str(res, result.size);
msgpack_pack_str_body(res, result.data, result.size);
if (result.size > 0) {
msgpack_pack_str_body(res, result.data, result.size);
}
}
typedef struct {

View File

@ -1575,7 +1575,9 @@ static char *shada_filename(const char *file)
do { \
const String s_ = (s); \
msgpack_pack_bin(spacker, s_.size); \
msgpack_pack_bin_body(spacker, s_.data, s_.size); \
if (s_.size > 0) { \
msgpack_pack_bin_body(spacker, s_.data, s_.size); \
} \
} while (0)
/// Write single ShaDa entry