diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-06-19 18:27:36 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-06-19 18:27:36 +0200 |
commit | 611893f7b9b39a0d3d4cb36d2af3924251af411b (patch) | |
tree | a550335daea38a830ca4ad15f01a5c77473eceec | |
parent | 2e2bfa31dc97159b7630c3c2913a49147be818d2 (diff) |
Fix a warning in using readlink
The use of the same buffer as input and output of readlink
leads to warnings due to restrict use in new versions of
GLIBC
Change-Id: Ifbf1277b88bd18a9df1e18211d4248e94c16d6da
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-hook.c | 12 | ||||
-rw-r--r-- | src/afb-trace.c | 31 |
2 files changed, 26 insertions, 17 deletions
diff --git a/src/afb-hook.c b/src/afb-hook.c index 75e8a691..d9fd1a37 100644 --- a/src/afb-hook.c +++ b/src/afb-hook.c @@ -735,26 +735,26 @@ static void hook_api_event_make_cb(void *closure, const struct afb_hookid *hooki static void hook_api_rootdir_get_fd_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result) { - char path[PATH_MAX]; + char path[PATH_MAX], proc[100]; if (result < 0) _hook_api_(export, "rootdir_get_fd() -> %d, %m", result); else { - sprintf(path, "/proc/self/fd/%d", result); - readlink(path, path, sizeof path); + snprintf(proc, sizeof proc, "/proc/self/fd/%d", result); + readlink(proc, path, sizeof path); _hook_api_(export, "rootdir_get_fd() -> %d = %s", result, path); } } static void hook_api_rootdir_open_locale_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *filename, int flags, const char *locale, int result) { - char path[PATH_MAX]; + char path[PATH_MAX], proc[100]; if (!locale) locale = "(null)"; if (result < 0) _hook_api_(export, "rootdir_open_locale(%s, %d, %s) -> %d, %m", filename, flags, locale, result); else { - sprintf(path, "/proc/self/fd/%d", result); - readlink(path, path, sizeof path); + snprintf(proc, sizeof proc, "/proc/self/fd/%d", result); + readlink(proc, path, sizeof path); _hook_api_(export, "rootdir_open_locale(%s, %d, %s) -> %d = %s", filename, flags, locale, result, path); } } diff --git a/src/afb-trace.c b/src/afb-trace.c index a603951c..5f54b174 100644 --- a/src/afb-trace.c +++ b/src/afb-trace.c @@ -685,33 +685,42 @@ static void hook_api_event_make(void *closure, const struct afb_hookid *hookid, static void hook_api_rootdir_get_fd(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result) { - char path[PATH_MAX]; + char path[PATH_MAX], proc[100]; + const char *key, *val; if (result >= 0) { - sprintf(path, "/proc/self/fd/%d", result); - readlink(path, path, sizeof path); + snprintf(proc, sizeof proc, "/proc/self/fd/%d", result); + readlink(proc, path, sizeof path); + key = "path"; + val = path; + } else { + key = "error"; + val = strerror(errno); } - hook_api(closure, hookid, export, "rootdir_get_fd", "{ss}", - result < 0 ? "path" : "error", - result < 0 ? strerror(errno) : path); + hook_api(closure, hookid, export, "rootdir_get_fd", "{ss}", key, val); } static void hook_api_rootdir_open_locale(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *filename, int flags, const char *locale, int result) { - char path[PATH_MAX]; + char path[PATH_MAX], proc[100]; + const char *key, *val; if (result >= 0) { - sprintf(path, "/proc/self/fd/%d", result); - readlink(path, path, sizeof path); + snprintf(proc, sizeof proc, "/proc/self/fd/%d", result); + readlink(proc, path, sizeof path); + key = "path"; + val = path; + } else { + key = "error"; + val = strerror(errno); } hook_api(closure, hookid, export, "rootdir_open_locale", "{ss si ss* ss}", "file", filename, "flags", flags, "locale", locale, - result < 0 ? "path" : "error", - result < 0 ? strerror(errno) : path); + key, val); } static void hook_api_queue_job(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result) |