aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-14 14:58:20 -0700
committerTobias Bosch <tbosch@google.com>2019-08-15 16:03:53 +0000
commit53b185a3187363605205925b04f986f20c1577a9 (patch)
tree948016c28c421eed86bd84efa0eb63509fdabd1c /compiler_wrapper
parent36c4a51a1c0e02be020cb1bb636169eea8a7ae92 (diff)
downloadtoolchain-utils-53b185a3187363605205925b04f986f20c1577a9.tar.gz
Properly escape stdout / stderr of nested commands
BUG=chromium:773875 TEST=unit test and comparison to old wrapper Change-Id: I47fdac56a7b8d972ccb4015222b533cb5e1e37ba Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1754128 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r--compiler_wrapper/oldwrapper.go6
-rw-r--r--compiler_wrapper/oldwrapper_test.go30
2 files changed, 34 insertions, 2 deletions
diff --git a/compiler_wrapper/oldwrapper.go b/compiler_wrapper/oldwrapper.go
index 5db47257..04458198 100644
--- a/compiler_wrapper/oldwrapper.go
+++ b/compiler_wrapper/oldwrapper.go
@@ -21,6 +21,8 @@ import (
const compareToOldWrapperFilePattern = "old_wrapper_compare"
func compareToOldWrapper(env env, cfg *config, inputCmd *command, newCmdResults []*commandResult, newExitCode int) error {
+ pythonStringEscaper := strings.NewReplacer("\n", "\\n", "'", "\\'")
+
oldWrapperCfg, err := newOldWrapperConfig(env, cfg, inputCmd)
if err != nil {
return err
@@ -29,8 +31,8 @@ func compareToOldWrapper(env env, cfg *config, inputCmd *command, newCmdResults
newCmds := []*command{}
for _, cmdResult := range newCmdResults {
oldWrapperCfg.CmdResults = append(oldWrapperCfg.CmdResults, oldWrapperCmdResult{
- Stdout: cmdResult.Stdout,
- Stderr: cmdResult.Stderr,
+ Stdout: pythonStringEscaper.Replace(cmdResult.Stdout),
+ Stderr: pythonStringEscaper.Replace(cmdResult.Stderr),
Exitcode: cmdResult.ExitCode,
})
newCmds = append(newCmds, cmdResult.Cmd)
diff --git a/compiler_wrapper/oldwrapper_test.go b/compiler_wrapper/oldwrapper_test.go
index 9a65168a..a7747ba7 100644
--- a/compiler_wrapper/oldwrapper_test.go
+++ b/compiler_wrapper/oldwrapper_test.go
@@ -217,6 +217,36 @@ func TestCompareToOldShellWrapperCompilerCommand(t *testing.T) {
})
}
+func TestCompareToOldWrapperEscapeStdoutAndStderr(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.cfg.mockOldWrapperCmds = false
+ ctx.cfg.oldWrapperPath = filepath.Join(ctx.tempDir, "fakewrapper")
+
+ ctx.cmdMock = func(cmd *command, stdout io.Writer, stderr io.Writer) error {
+ io.WriteString(stdout, "a\n'b'")
+ io.WriteString(stderr, "c\n'd'")
+ writePythonMockWrapper(ctx, &mockWrapperConfig{
+ Cmds: []*mockWrapperCmd{
+ {
+ Path: cmd.Path,
+ Args: cmd.Args,
+ },
+ },
+ })
+ return nil
+ }
+
+ ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(clangX86_64, mainCc)))
+ if ctx.stdoutString() != "a\n'b'" {
+ t.Errorf("unexpected stdout. Got: %s", ctx.stdoutString())
+ }
+ if ctx.stderrString() != "c\n'd'" {
+ t.Errorf("unexpected stderr. Got: %s", ctx.stderrString())
+ }
+ })
+}
+
func writePythonMockWrapper(ctx *testContext, cfg *mockWrapperConfig) {
const mockTemplate = `
from __future__ import print_function