From 3af3f87ee045ee52f635aaa63ea58ecfed6a7cd1 Mon Sep 17 00:00:00 2001 From: faust747 Date: Thu, 10 Apr 2025 18:06:58 +0300 Subject: [PATCH] Docker: fix quoting logic in withDockerExecCmd: use host OS instead of container OS The function withDockerExecCmd previously used the OS type of the Docker container to determine the quoting style (i.e. single vs. double quotes) when composing shell commands. On Windows this led to single quotes being used in commands. Commands with single quotes cannot be executed in cmd.exe. OStype is still used in "CommandLine testType" Change-Id: I0a44bd1085df9cc4f0bb7466f056bb97cedf0b37 Reviewed-by: hjk --- src/plugins/docker/dockerdevice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 904c7cd4fcf..9a9e8d8ea82 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -776,10 +776,6 @@ Result DockerDevicePrivate::withDockerExecCmd( else containerId = *result; - auto osAndArch = osTypeAndArch(); - if (!osAndArch) - return make_unexpected(osAndArch.error()); - CommandLine dockerCmd{settings().dockerBinaryPath(), {"exec"}}; if (interactive) @@ -802,12 +798,16 @@ Result DockerDevicePrivate::withDockerExecCmd( dockerCmd.addArg(containerId); - dockerCmd.addArgs({"/bin/sh", "-c"}, osAndArch->first); + dockerCmd.addArgs({"/bin/sh", "-c"}); CommandLine exec("exec"); exec.addCommandLineAsArgs(cmd, CommandLine::Raw); if (withMarker) { + auto osAndArch = osTypeAndArch(); + if (!osAndArch) + return make_unexpected(osAndArch.error()); + // Check the executable for existence. CommandLine testType({"type", {}}); testType.addArg(cmd.executable().path(), osAndArch->first); @@ -821,9 +821,9 @@ Result DockerDevicePrivate::withDockerExecCmd( testType.addCommandLineWithAnd(echo); - dockerCmd.addCommandLineAsSingleArg(testType, osAndArch->first); + dockerCmd.addCommandLineAsSingleArg(testType); } else { - dockerCmd.addCommandLineAsSingleArg(exec, osAndArch->first); + dockerCmd.addCommandLineAsSingleArg(exec); } return dockerCmd;