Skip to content

Commit

Permalink
added missing byte 0xFF into hex2intTable. This fixes panic when deco…
Browse files Browse the repository at this point in the history
…ding specially crafted string like "%\xff"
  • Loading branch information
valyala committed Dec 7, 2017
1 parent 51bb002 commit e5f51c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 21 additions & 0 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ import (
"time"
)

func TestDecodeArgAppend(t *testing.T) {
testDecodeArgAppend(t, "", "")
testDecodeArgAppend(t, "foobar", "foobar")
testDecodeArgAppend(t, "тест", "тест")
testDecodeArgAppend(t, "a%", "a%")
testDecodeArgAppend(t, "%a%21", "%a!")
testDecodeArgAppend(t, "ab%test", "ab%test")
testDecodeArgAppend(t, "d%тестF", "d%тестF")
testDecodeArgAppend(t, "a%\xffb%20c", "a%\xffb c")
testDecodeArgAppend(t, "foo%20bar", "foo bar")
testDecodeArgAppend(t, "f.o%2C1%3A2%2F4=%7E%60%21%40%23%24%25%5E%26*%28%29_-%3D%2B%5C%7C%2F%5B%5D%7B%7D%3B%3A%27%22%3C%3E%2C.%2F%3F",
"f.o,1:2/4=~`!@#$%^&*()_-=+\\|/[]{};:'\"<>,./?")
}

func testDecodeArgAppend(t *testing.T, s, expectedResult string) {
result := decodeArgAppend(nil, []byte(s))
if string(result) != expectedResult {
t.Fatalf("unexpected decodeArgAppend(%q)=%q; expecting %q", s, result, expectedResult)
}
}

func TestArgsAdd(t *testing.T) {
var a Args
a.Add("foo", "bar")
Expand Down
10 changes: 5 additions & 5 deletions bytesconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,15 @@ func hexCharUpper(c byte) byte {
}

var hex2intTable = func() []byte {
b := make([]byte, 255)
for i := byte(0); i < 255; i++ {
b := make([]byte, 256)
for i := 0; i < 256; i++ {
c := byte(16)
if i >= '0' && i <= '9' {
c = i - '0'
c = byte(i) - '0'
} else if i >= 'a' && i <= 'f' {
c = i - 'a' + 10
c = byte(i) - 'a' + 10
} else if i >= 'A' && i <= 'F' {
c = i - 'A' + 10
c = byte(i) - 'A' + 10
}
b[i] = c
}
Expand Down

1 comment on commit e5f51c1

@erikdubbelboer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good @valyala, I see you do pay some attention to my commits, erikdubbelboer@4f82d07 and much older pull request #248.

Please sign in to comment.