From 885885bfa41c56f7615d635d348ba7cec34b4684 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Tue, 28 Aug 2012 00:01:39 -0400 Subject: [PATCH] Fix: check return value of get_char_array Arrays that are not char arrays will cause a segfault if we don't check the return value of get_char_array before accessing the str pointer. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- formats/ctf/events.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 890956e9..efcd6f05 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -515,12 +515,18 @@ int64_t bt_ctf_get_int64(const struct definition *field) char *bt_ctf_get_char_array(const struct definition *field) { char *ret = NULL; + GString *char_array; - if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) - ret = get_char_array(field)->str; - else - bt_ctf_field_set_error(-EINVAL); + if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) { + char_array = get_char_array(field); + if (char_array) { + ret = char_array->str; + goto end; + } + } + bt_ctf_field_set_error(-EINVAL); +end: return ret; } -- 2.34.1