]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #786: memccpy() detects buffer overlap on macOS
authorArun Prakash Jana <engineerarun@gmail.com>
Thu, 19 Nov 2020 04:07:18 +0000 (09:37 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 19 Nov 2020 04:08:17 +0000 (09:38 +0530)
src/nnn.c

index 8328718ce2734e38cd04895c64d310566435ada4..4be553acb56354f54a880acaccde1ee190b29bb8 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1016,6 +1016,8 @@ static inline bool getutil(char *util)
 /*
  * Updates out with "dir/name or "/name"
  * Returns the number of bytes copied including the terminating NULL byte
+ *
+ * Note: dir and out must be PATH_MAX in length to avoid macOS fault
  */
 static size_t mkpath(const char *dir, const char *name, char *out)
 {
@@ -4710,10 +4712,14 @@ static bool run_cmd_as_plugin(const char *file, char *runfile, uchar flags)
 
 static bool plctrl_init(void)
 {
-       snprintf(g_buf, CMD_LEN_MAX, "nnn-pipe.%d", getpid());
+       size_t len;
+
        /* g_tmpfpath is used to generate tmp file names */
        g_tmpfpath[tmpfplen - 1] = '\0';
-       mkpath(g_tmpfpath, g_buf, g_pipepath);
+       len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX);
+       g_pipepath[len - 1] = '/';
+       len = xstrsncpy(g_pipepath + len, "nnn-pipe.", TMP_LEN_MAX - len) + len;
+       xstrsncpy(g_pipepath + len - 1, xitoa(getpid()), TMP_LEN_MAX - len);
        setenv(env_cfg[NNN_PIPE], g_pipepath, TRUE);
 
        return EXIT_SUCCESS;