diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-04-13 14:50:36 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-04-13 23:02:25 +0200 |
commit | 062887f854dba260a2fc12bd4c388baea65f524a (patch) | |
tree | d5f9e4ca2e87e322d6c8b115efed17e89e68311a | |
parent | 11be2254c0cd1cacc9ff5d8c9c031e4ed72d8a31 (diff) |
secure subcall api and verb
Change-Id: Ia1df54bfd139f247137f4373a2cbd75dcf74efc8
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-subcall.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/afb-subcall.c b/src/afb-subcall.c index a75cbdd0..68b33129 100644 --- a/src/afb-subcall.c +++ b/src/afb-subcall.c @@ -89,18 +89,25 @@ static int subcall_unsubscribe(struct afb_xreq *xreq, struct afb_event event) static struct subcall *create_subcall(struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure) { struct subcall *subcall; + size_t lenapi, lenverb; + char *copy; - subcall = calloc(1, sizeof *subcall); + lenapi = 1 + strlen(api); + lenverb = 1 + strlen(verb); + subcall = malloc(lenapi + lenverb + sizeof *subcall); if (subcall == NULL) { return NULL; } - afb_xreq_init(&subcall->xreq, &afb_subcall_xreq_itf); afb_context_subinit(&subcall->xreq.context, &caller->context); subcall->xreq.cred = afb_cred_addref(caller->cred); subcall->xreq.json = args; - subcall->xreq.api = api; /* TODO: alloc ? */ - subcall->xreq.verb = verb; /* TODO: alloc ? */ + copy = (char*)&subcall[1]; + memcpy(copy, api, lenapi); + subcall->xreq.api = copy; + copy = ©[lenapi]; + memcpy(copy, verb, lenverb); + subcall->xreq.verb = copy; subcall->caller = caller; subcall->callback = callback; subcall->closure = closure; |