From: Mathieu Desnoyers Date: Mon, 26 Nov 2012 20:58:08 +0000 (-0500) Subject: Clarify empty string/NULL filter errors X-Git-Tag: v2.1.0-rc9~9 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=52df24019c3998b87870fb8371fa20fb33449a0d Clarify empty string/NULL filter errors Fixes #404 Reported-by: Jesus Garcia Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index c6fc60558..515e07c4e 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -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, diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index df4760602..d5cfc0e27 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -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; diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 6238d9a00..96351bdcf 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -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; }