Fix: check return value of get_char_array
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 28 Aug 2012 04:01:39 +0000 (00:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 28 Aug 2012 04:01:39 +0000 (00:01 -0400)
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 <jdesfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/events.c

index 890956e9f919884441ec6e7c5b80dd4b4a5d3355..efcd6f05fafb62e4a7b63856308315a352e534bd 100644 (file)
@@ -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;
 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;
 }
 
        return ret;
 }
 
This page took 0.024883 seconds and 4 git commands to generate.