Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter_lua: validate lua function #600

Merged
merged 1 commit into from May 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugins/filter_lua/lua.c
Expand Up @@ -106,6 +106,19 @@ int msgpack_map_to_json(struct lua_filter *lf, msgpack_object *obj)
return 0;
}

static int is_valid_func(struct flb_luajit *lua, flb_sds_t func)
{
int ret = FLB_FALSE;

lua_getglobal(lua, func);
if (lua_isfunction(lua, -1)) {
ret = FLB_TRUE;
}
lua_pop(lua, -1); /* discard return value of isfunction */

return ret;
}

static int cb_lua_init(struct flb_filter_instance *f_ins,
struct flb_config *config,
void *data)
Expand Down Expand Up @@ -137,6 +150,13 @@ static int cb_lua_init(struct flb_filter_instance *f_ins,
}
lua_pcall(ctx->lua->state, 0, 0, 0);

if (is_valid_func(ctx->lua->state, ctx->call) != FLB_TRUE) {
flb_error("[filter_lua] function %s is not found", ctx->call);

lua_config_destroy(ctx);
return -1;
}

/* Set context */
flb_filter_set_context(f_ins, ctx);

Expand Down