plugin: fix leaking invoked method name for exec plugins

The invoked method name was separately duplicated from the call_context
structure. The structure itself is eventually freed by rpc_exec_reply()
but the method string it points to is lost after that.

Use calloc_a() instead to allocate the string copy buffer together with
the context structure, to ensure that all involved memory is freed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-10-17 11:50:39 +02:00
parent 95f0973c34
commit 37aa9196b6

View file

@ -135,14 +135,14 @@ rpc_plugin_call(struct ubus_context *ctx, struct ubus_object *obj,
{ {
int rv = UBUS_STATUS_UNKNOWN_ERROR; int rv = UBUS_STATUS_UNKNOWN_ERROR;
struct call_context *c; struct call_context *c;
char *plugin; char *plugin, *mptr;
c = calloc(1, sizeof(*c)); c = calloc_a(sizeof(*c), &mptr, strlen(method) + 1);
if (!c) if (!c)
goto fail; goto fail;
c->method = strdup(method); c->method = strcpy(mptr, method);
c->input = blobmsg_format_json(msg, true); c->input = blobmsg_format_json(msg, true);
c->tok = json_tokener_new(); c->tok = json_tokener_new();