summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-10-17 11:50:39 +0200
committerJo-Philipp Wich <jo@mein.io>2020-05-26 16:18:26 +0200
commitd80f70eb4af0ad447f7d34c5b9198e4fece7da57 (patch)
tree6a6ee2d327d7555fc66ce9bd59bb97f431a5a9ba
parent53a0952a4b51408af8856d3a59106bc037ac35bd (diff)
downloadrpcd-d80f70eb4af0ad447f7d34c5b9198e4fece7da57.tar.gz
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> (cherry picked from commit 37aa9196b603769ffbff4d0c58f76259a3791384)
-rw-r--r--plugin.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/plugin.c b/plugin.c
index 3740622..fa5f09f 100644
--- a/plugin.c
+++ b/plugin.c
@@ -135,14 +135,14 @@ rpc_plugin_call(struct ubus_context *ctx, struct ubus_object *obj,
{
int rv = UBUS_STATUS_UNKNOWN_ERROR;
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)
goto fail;
- c->method = strdup(method);
+ c->method = strcpy(mptr, method);
c->input = blobmsg_format_json(msg, true);
c->tok = json_tokener_new();