]> Sergey Matveev's repositories - nnn.git/commitdiff
Concatenate arguments to pass to `sh`
authorArun <engineerarun@gmail.com>
Sun, 15 Jan 2023 05:29:36 +0000 (10:59 +0530)
committerGitHub <noreply@github.com>
Sun, 15 Jan 2023 05:29:36 +0000 (10:59 +0530)
Co-authored-by: KlzXS <klzx+github@klzx.cf>
Co-authored-by: Arun Prakash Jana <engineerarun@gmail.com>
src/nnn.c

index 4b2d0a3d659fff1622329daea787abc7681e897f..c70392bb47e998a65ecfcba41a4ae1541343c9bb 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4490,12 +4490,29 @@ static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool page)
        pid = fork();
        if (pid == 0) {
                /* In child */
+               char *bufptr = file;
+
                close(cmd_in_fd);
                dup2(cmd_out_fd, STDOUT_FILENO);
                dup2(cmd_out_fd, STDERR_FILENO);
                close(cmd_out_fd);
 
-               spawn(utils[UTIL_SH_EXEC], file, arg1, arg2, F_MULTI);
+               if (bufptr && arg1) {
+                       char argbuf[CMD_LEN_MAX];
+
+                       len = xstrsncpy(argbuf, file, xstrlen(file) + 1);
+                       argbuf[len - 1] = ' ';
+                       bufptr = argbuf + len;
+                       len = xstrsncpy(bufptr, arg1, xstrlen(arg1) + 1);
+                       if (arg2) {
+                               bufptr[len - 1] = ' ';
+                               xstrsncpy(bufptr + len, arg2, xstrlen(arg2) + 1);
+                       }
+
+                       bufptr = argbuf;
+               }
+
+               spawn(utils[UTIL_SH_EXEC], bufptr, NULL, NULL, F_MULTI);
                _exit(EXIT_SUCCESS);
        }