Fix: __string() and tp_strcpy() should handle NULL pointers
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 16 May 2016 20:58:11 +0000 (16:58 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 16 May 2016 20:58:11 +0000 (16:58 -0400)
The regmap instrumentation can send a NULL string (e.g. on ARM32).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
probes/lttng-events.h

index f6f7ef1c3bebb1a6b953d7f44f94164d9018b53b..db445f1adea405038b55b8dea2e56e7769e0e6d9 100644 (file)
@@ -28,6 +28,8 @@
 #include "../lttng-events.h"
 #include "../lttng-tracer-core.h"
 
+#define __LTTNG_NULL_STRING    "(null)"
+
 /*
  * Macro declarations used for all stages.
  */
@@ -505,7 +507,8 @@ static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
 
 #undef __string
 #define __string(_item, _src)                                                 \
-       __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
+       __event_len += __dynamic_len[__dynamic_len_idx++] =                    \
+               strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1;
 
 /*
  * strlen_user includes \0. If returns 0, it faulted, so we set size to
@@ -814,8 +817,12 @@ __assign_##dest:                                                   \
 __assign_##dest:                                                       \
        if (0)                                                          \
                (void) __typemap.dest;                                  \
-       lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
-       __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
+       {                                                               \
+               const char *__ctf_tmp_string =                          \
+                       ((src) ? (src) : __LTTNG_NULL_STRING);          \
+               lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
+               __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, __get_dynamic_array_len(dest)); \
+       }                                                               \
        goto __end_field_##dest;
 
 /* Named field types must be defined in lttng-types.h */
This page took 0.027126 seconds and 4 git commands to generate.