Skip to content

Commit

Permalink
Bugfix: invalid attribute values gave out-of-bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 14, 2015
1 parent b4161f8 commit 5bc9130
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions html/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ func TestAttrVal(t *testing.T) {
assertAttrVal(t, "'x"z'", "'x\"z'")
assertAttrVal(t, "'x\">'", "'x\">'")
assertAttrVal(t, "You're encouraged to log in; however, it's not mandatory. [o]", "\"You're encouraged to log in; however, it's not mandatory. [o]\"")
assertAttrVal(t, "a'b=\"\"", "'a'b=\"\"'")
}
9 changes: 6 additions & 3 deletions xml/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ func EscapeAttrVal(buf *[]byte, b []byte) []byte {
}
}

n := len(b) + 2
var quote byte
var escapedQuote []byte
if doubles > singles {
n += singles * 4
quote = '\''
escapedQuote = singleQuoteEntityBytes
} else {
n += doubles * 4
quote = '"'
escapedQuote = doubleQuoteEntityBytes
}
if len(b)+2 > cap(*buf) {
*buf = make([]byte, 0, len(b)+2) // maximum size, not actual size
if n > cap(*buf) {
*buf = make([]byte, 0, n) // maximum size, not actual size
}
t := (*buf)[:len(b)+2] // maximum size, not actual size
t := (*buf)[:n] // maximum size, not actual size
t[0] = quote
j := 1
start := 0
Expand Down
1 change: 1 addition & 0 deletions xml/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ func TestAttrVal(t *testing.T) {
assertAttrVal(t, "x&z", "\"x&z\"")
assertAttrVal(t, "x'z", "\"x'z\"")
assertAttrVal(t, "x\"z", "'x\"z'")
assertAttrVal(t, "a'b=\"\"", "'a'b=\"\"'")
}

0 comments on commit 5bc9130

Please sign in to comment.