From 8cf70900e75d38d6c38726f85ffec74d100efbdb Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Wed, 18 Mar 2020 11:42:39 +0900 Subject: [PATCH] mcexec: Fix LD_PRELOAD string manipulation To suppress compiler warnings. Change-Id: I4d6b5ce2d2a8fca3f2675a7fc309df40cfe3c04b --- executer/user/mcexec.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 0efb16d9..37794d78 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -1933,7 +1933,15 @@ opendev() } #define LD_PRELOAD_PREPARE(name) do { \ - sprintf(elembuf, "%s%s/" name, nelem > 0 ? ":" : "", libdir); \ + int n = 0;\ + \ + n += snprintf(elembuf, PATH_MAX, "%s", nelem > 0 ? ":" : ""); \ + strncat(elembuf, libdir, PATH_MAX - n); \ + n = n + strlen(libdir) > PATH_MAX ? \ + PATH_MAX : n + strlen(libdir); \ + strncat(elembuf, "/", PATH_MAX - n); \ + n = n + 1 > PATH_MAX ? PATH_MAX : n + 1; \ + strncat(elembuf, name, PATH_MAX - n); \ } while (0) #define LD_PRELOAD_APPEND do { \