From cd3d69d20fcdbb7eabd0ad8099e0cc7c54eaf344 Mon Sep 17 00:00:00 2001 From: Jose Diez Date: Fri, 27 Jan 2017 17:09:20 +0000 Subject: [PATCH] Problem: _dup() strdup a null pointer Solution: add a check to only strdup non-null strings --- src/zproto_codec_c.gsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/zproto_codec_c.gsl b/src/zproto_codec_c.gsl index c403d1f..516ffef 100644 --- a/src/zproto_codec_c.gsl +++ b/src/zproto_codec_c.gsl @@ -679,7 +679,12 @@ $(class.name)_dup ($(class.name)_t *other) // Copy the rest of the fields .for class.field . if type = "longstr" - $(class.name)_set_$(name) (copy, strdup ($(class.name)_$(name) (other))); + { + const char *str = $(class.name)_$(name) (other); + if (str) { + $(class.name)_set_$(name) (copy, strdup (str)); + } + } . elsif type = "uuid" | type = "hash" | type = "chunk" | type = "frame" | type = "msg" $(class.name)_set_$(name) (copy, z$(type)_dup ($(class.name)_$(name) (other))); . elsif type = "strings"