Skip to content

Commit

Permalink
Merge pull request percona#54 from zanjie/master
Browse files Browse the repository at this point in the history
fix fi overflow cause index out of range panic
  • Loading branch information
percona-csalguero authored May 11, 2020
2 parents ad5b035 + 30c3368 commit cd2547b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func Fingerprint(q string) string {
if Debug {
fmt.Println("Lost in space")
}
if fi > 0 && !isSpace(rune(f[fi-1])) {
if fi <= len(f)-1 && fi > 0 && !isSpace(rune(f[fi-1])) {
if Debug {
fmt.Println("Add space")
}
Expand Down Expand Up @@ -772,7 +772,7 @@ func Fingerprint(q string) string {
addSpace = false
s = inValues
sqlState = inValues
} else if addSpace {
} else if addSpace && fi <= len(f)-1 {
if Debug {
fmt.Println("Add space")
}
Expand Down
14 changes: 14 additions & 0 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,20 @@ func TestFingerprintPanicChallenge2(t *testing.T) {
"select ? ? ? ? from kamil",
query.Fingerprint(q),
)

q = "delete from db.table where col1 in(1) and col2=1"
assert.Equal(
t,
"delete from db.table where col1 in(?+) and col2=?",
query.Fingerprint(q),
)

q = "delete from db.table where col1 in(1) and col2=1;"
assert.Equal(
t,
"delete from db.table where col1 in(?+) and col2=?;",
query.Fingerprint(q),
)
}

func TestFingerprintDashesInNames(t *testing.T) {
Expand Down

0 comments on commit cd2547b

Please sign in to comment.