[tex-k] Patch: Fix spaces in arguments of runscript.exe

Naveen M K naveen at syrusdark.website
Mon Jun 7 20:45:19 CEST 2021


Hi,

I am the maintainer of MSYS2-MINGW TexLive packages, I got a report[0], 
that command line arguments aren't passed correctly to underlying 
scripts. I have come up with a patch for fixing that. I have attached them.

Ciao,
Naveen M K


[0].. https://github.com/msys2/MINGW-packages/issues/8821
-------------- next part --------------
From b58d6e526ca16249dff680811e29ac6c646fa35e Mon Sep 17 00:00:00 2001
From: Naveen M K <naveen at syrusdark.website>
Date: Mon, 7 Jun 2021 23:42:01 +0530
Subject: [PATCH] runscript: always quote args

Signed-off-by: Naveen M K <naveen at syrusdark.website>
---
 .../texlive/w64_mingw_wrapper/runscript_dll.c | 34 ++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/texk/texlive/w64_mingw_wrapper/runscript_dll.c b/texk/texlive/w64_mingw_wrapper/runscript_dll.c
index 588c84b9..a4fd7acc 100644
--- a/texk/texlive/w64_mingw_wrapper/runscript_dll.c
+++ b/texk/texlive/w64_mingw_wrapper/runscript_dll.c
@@ -22,6 +22,38 @@ char subsys_mode[] = "CUI_MODE\n";
 char err_env_var[] = "RUNSCRIPT_ERROR_MESSAGE";
 char msg_buf[MAX_MSG];
 
+char *quote(char *data) {
+    int i, ln = strlen(data), nb;
+
+    /* We allocate twice as much space as needed to deal with worse-case
+       of having to escape everything. */
+    char *result = calloc(ln*2+3, sizeof(char));
+    char *presult = result;
+
+    *presult++ = '"';
+    for (nb=0, i=0; i < ln; i++)
+      {
+        if (data[i] == '\\')
+          nb += 1;
+        else if (data[i] == '"')
+          {
+            for (; nb > 0; nb--)
+              *presult++ = '\\';
+            *presult++ = '\\';
+          }
+        else
+          nb = 0;
+        *presult++ = data[i];
+      }
+
+    for (; nb > 0; nb--)        /* Deal w trailing slashes */
+      *presult++ = '\\';
+
+    *presult++ = '"';
+    *presult++ = 0;
+    return result;
+}
+
 
 __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) 
 {
@@ -69,7 +101,7 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
   lua_argv = (char **)malloc( (argc + 6) * sizeof(char *) );
   lua_argv[lua_argc=0] = texlua_name;
   lua_argv[++lua_argc] = fpath; // script to execute
-  for ( k = 1; k < argc; k++ ) lua_argv[++lua_argc] = argv[k]; // copy argument list
+  for ( k = 1; k < argc; k++ ) lua_argv[++lua_argc] = quote(argv[k]); // copy argument list
   lua_argv[++lua_argc] = subsys_mode; // sentinel argument
   lua_argv[++lua_argc] = argc ? argv[0] : own_path; // original argv[0]
   //lua_argv[++lua_argc] = argline; // unparsed arguments
-- 
2.31.1.windows.1



More information about the tex-k mailing list.