desktop/win32/source/officeloader/officeloader.cxx |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

New commits:
commit 9649057c4c0d0e81ac46d41849ab9d0134a84de0
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Oct 1 21:29:47 2018 +0300
Commit:     Tor Lillqvist <t...@collabora.com>
CommitDate: Wed Apr 10 22:09:36 2019 +0200

    tdf#120249: escape trailing backslash in argument passed to soffice.bin
    
    ... to avoid treating \" as in-argument " instead of end of argument
    
    See 
https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw
    
    Change-Id: Ie283ba04117e13bc06c5b92412a945f945e67ff3
    Reviewed-on: https://gerrit.libreoffice.org/61214
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit f4103a42d58535e21c48ff94ab000ab0305c62e3)
    Reviewed-on: https://gerrit.libreoffice.org/61222
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 9bb9be742d74d412d27be3db4ce5ac5e9508cb5b)
    Reviewed-on: https://gerrit.libreoffice.org/70524
    Reviewed-by: Tor Lillqvist <t...@collabora.com>
    Tested-by: Tor Lillqvist <t...@collabora.com>

diff --git a/desktop/win32/source/officeloader/officeloader.cxx 
b/desktop/win32/source/officeloader/officeloader.cxx
index 45b94a8e128d..77c9a063532d 100644
--- a/desktop/win32/source/officeloader/officeloader.cxx
+++ b/desktop/win32/source/officeloader/officeloader.cxx
@@ -71,7 +71,7 @@ int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
             argv = GetCommandArgs(&argc);
             std::size_t n = wcslen(argv[0]) + 2;
             for (int i = 1; i < argc; ++i) {
-                n += wcslen(argv[i]) + 3;
+                n += wcslen(argv[i]) + 4; // 2 doublequotes + a space + 
optional trailing backslash
             }
             n += MY_LENGTH(L" \"-env:OOO_CWD=2") + 4 * cwdLen +
                 MY_LENGTH(L"\"") + 1;
@@ -86,6 +86,13 @@ int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
             if (bFirst || EXITHELPER_NORMAL_RESTART == dwExitCode || 
wcsncmp(argv[i], MY_STRING(L"-env:")) == 0) {
                 p = desktop_win32::commandLineAppend(p, MY_STRING(L"\" \""));
                 p = desktop_win32::commandLineAppend(p, argv[i]);
+                const size_t arglen = wcslen(argv[i]);
+                // tdf#120249: if an argument ends with backslash, we should 
escape it with another
+                // backslash; otherwise, the trailing backslash will be 
treated as an escapement
+                // character for the following doublequote by 
CommandLineToArgvW in soffice.bin. See
+                // 
https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw
+                if (arglen && argv[i][arglen-1] == '\\')
+                    p = desktop_win32::commandLineAppend(p, MY_STRING(L"\\"));
             }
         }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to