afb-hook & afb-trace: Fix usage of readlink
[src/app-framework-binder.git] / src / afb-trace.c
index 5f54b17..e7ae9fc 100644 (file)
@@ -489,7 +489,7 @@ static void hook_xreq_get_uid(void *closure, const struct afb_hookid *hookid, co
 
 static void hook_xreq_get_client_info(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *result)
 {
-       hook_xreq(closure, hookid, xreq, "get_client_info", "{so}",
+       hook_xreq(closure, hookid, xreq, "get_client_info", "{sO}",
                                        "result", result);
 }
 
@@ -687,10 +687,12 @@ static void hook_api_rootdir_get_fd(void *closure, const struct afb_hookid *hook
 {
        char path[PATH_MAX], proc[100];
        const char *key, *val;
+       ssize_t s;
 
        if (result >= 0) {
                snprintf(proc, sizeof proc, "/proc/self/fd/%d", result);
-               readlink(proc, path, sizeof path);
+               s = readlink(proc, path, sizeof path);
+               path[s < 0 ? 0 : s >= sizeof path ? sizeof path - 1 : s] = 0;
                key = "path";
                val = path;
        } else {
@@ -705,10 +707,12 @@ static void hook_api_rootdir_open_locale(void *closure, const struct afb_hookid
 {
        char path[PATH_MAX], proc[100];
        const char *key, *val;
+       ssize_t s;
 
        if (result >= 0) {
                snprintf(proc, sizeof proc, "/proc/self/fd/%d", result);
-               readlink(proc, path, sizeof path);
+               s = readlink(proc, path, sizeof path);
+               path[s < 0 ? 0 : s >= sizeof path ? sizeof path - 1 : s] = 0;
                key = "path";
                val = path;
        } else {
@@ -1739,7 +1743,7 @@ int afb_trace_add(afb_req_t req, struct json_object *args, struct afb_trace *tra
 }
 
 /* drop traces */
-extern int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
+int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
 {
        int rc;
        struct context context;