Clarify empty string/NULL filter errors
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 26 Nov 2012 20:58:08 +0000 (15:58 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 26 Nov 2012 20:59:57 +0000 (15:59 -0500)
Fixes #404

Reported-by: Jesus Garcia <jesus.garcia@ericsson.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
include/lttng/lttng.h
src/bin/lttng-sessiond/main.c
src/lib/lttng-ctl/lttng-ctl.c

index c6fc60558ae833a5fe011147d24ec75f10b20b5c..515e07c4e9703653c600e633d887ccae6f194957 100644 (file)
@@ -516,6 +516,8 @@ extern int lttng_enable_event(struct lttng_handle *handle,
  * If event_name is NULL, all events are enabled with that filter.
  * If channel_name is NULL, the default channel is used (channel0) and created
  * if not found.
+ * If filter_expression is NULL, an event without associated filter is
+ * created.
  */
 extern int lttng_enable_event_with_filter(struct lttng_handle *handle,
                struct lttng_event *event, const char *channel_name,
index df4760602b5e4838f90cf124764fbbdad06d5ef4..d5cfc0e2769e58a6b13b0870ef2dace8b0a59c85 100644 (file)
@@ -2853,6 +2853,10 @@ skip_domain:
                        ret = LTTNG_ERR_FILTER_INVAL;
                        goto error;
                }
+               if (cmd_ctx->lsm->u.enable.bytecode_len == 0) {
+                       ret = LTTNG_ERR_FILTER_INVAL;
+                       goto error;
+               }
                bytecode = zmalloc(cmd_ctx->lsm->u.enable.bytecode_len);
                if (!bytecode) {
                        ret = LTTNG_ERR_FILTER_NOMEM;
index 6238d9a00749865e23e390c2ac87b9e8799a09af..96351bdcf25b81318e8af78bcd1a5fc742a21a22 100644 (file)
@@ -841,8 +841,20 @@ int lttng_enable_event_with_filter(struct lttng_handle *handle,
        FILE *fmem;
        int ret = 0;
 
-       /* Safety check. */
-       if (handle == NULL || !filter_expression) {
+       if (!filter_expression) {
+               /*
+                * Fall back to normal event enabling if no filter
+                * specified.
+                */
+               return lttng_enable_event(handle, event, channel_name);
+       }
+
+       /*
+        * Empty filter string will always be rejected by the parser
+        * anyway, so treat this corner-case early to eliminate
+        * lttng_fmemopen error for 0-byte allocation.
+        */
+       if (handle == NULL || filter_expression[0] == '\0') {
                return -LTTNG_ERR_INVALID;
        }
 
This page took 0.029897 seconds and 4 git commands to generate.