Commit 97c859f8 authored by Michal Bohuslávek's avatar Michal Bohuslávek Committed by Russ Cox

encoding/xml: reject invalid comments

Fixes #11112.

Change-Id: I16e7363549a0dec8c61addfa14af0866c1fd7c40
Reviewed-on: https://go-review.googlesource.com/14173Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 3f6b91b1
......@@ -712,3 +712,24 @@ func TestUnmarshalIntoInterface(t *testing.T) {
t.Errorf("failed to unmarshal into interface, have %q want %q", have, want)
}
}
type X struct {
D string `xml:",comment"`
}
// Issue 11112. Unmarshal must reject invalid comments.
func TestMalformedComment(t *testing.T) {
testData := []string{
"<X><!-- a---></X>",
"<X><!-- -- --></X>",
"<X><!-- a--b --></X>",
"<X><!------></X>",
}
for i, test := range testData {
data := []byte(test)
v := new(X)
if err := Unmarshal(data, v); err == nil {
t.Errorf("%d: unmarshal should reject invalid comments", i)
}
}
}
......@@ -624,7 +624,12 @@ func (d *Decoder) rawToken() (Token, error) {
return nil, d.err
}
d.buf.WriteByte(b)
if b0 == '-' && b1 == '-' && b == '>' {
if b0 == '-' && b1 == '-' {
if b != '>' {
d.err = d.syntaxError(
`invalid sequence "--" not allowed in comments`)
return nil, d.err
}
break
}
b0, b1 = b1, b
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment