Skip to content

Commit

Permalink
mw: fix transform middleware regression with XML
Browse files Browse the repository at this point in the history
This was a crash in the mxj library concerning invalid input from a
reader, as it would not properly error and stop. We did not hit this
before in 2.3.x as we used a []byte, not an io.Reader.

The upstream issue is clbanning/mxj#38, fixed
back in February.

Add a regression test and bump the vendored version.

Fixes #1122.
  • Loading branch information
mvdan authored and buger committed Sep 29, 2017
1 parent be97a94 commit 286a8db
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 95 deletions.
14 changes: 14 additions & 0 deletions mw_transform_test.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"io/ioutil"
"strings"
"testing"
"text/template"

Expand Down Expand Up @@ -31,3 +32,16 @@ func TestTransformNonAscii(t *testing.T) {
t.Fatalf("wanted body %q, got %q", want, got)
}
}

func TestTransformXMLCrash(t *testing.T) {
// mxj.NewMapXmlReader used to take forever and crash the
// process by eating up all the memory.
in := strings.NewReader("")
r := testReq(t, "GET", "/", in)
tmeta := &TransformSpec{}
tmeta.TemplateData.Input = apidef.RequestXML
tmeta.Template = template.Must(template.New("blob").Parse(""))
if err := transformBody(r, tmeta, false); err == nil {
t.Fatalf("wanted error, got nil")
}
}
16 changes: 12 additions & 4 deletions vendor/github.com/clbanning/mxj/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions vendor/github.com/clbanning/mxj/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions vendor/github.com/clbanning/mxj/keyvalues.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions vendor/github.com/clbanning/mxj/leafnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/clbanning/mxj/newmap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions vendor/github.com/clbanning/mxj/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/clbanning/mxj/rename.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/clbanning/mxj/setfieldsep.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions vendor/github.com/clbanning/mxj/struct.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 286a8db

Please sign in to comment.