From d549e748592b58ae4046470bf17d11cfb5be3e97 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Jun 2021 19:44:21 +0800 Subject: [PATCH] fix fi overflow panic because of multi 'in values' in query text --- query/query.go | 3 +++ query/query_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/query/query.go b/query/query.go index 576014d..3efe9c6 100644 --- a/query/query.go +++ b/query/query.go @@ -379,6 +379,9 @@ func Fingerprint(q string) string { valueNo++ if valueNo == 1 { if qi-firstPar > 1 { + if qi-firstPar == 2 { + f = append(f, 0) + } copy(f[fi:fi+4], "(?+)") fi += 4 } else { diff --git a/query/query_test.go b/query/query_test.go index 3fcbd31..be10973 100644 --- a/query/query_test.go +++ b/query/query_test.go @@ -556,6 +556,13 @@ func TestFingerprintPanicChallenge2(t *testing.T) { query.Fingerprint(q), ) + q = "select col1 from tb1 where cond1 in(1) and cond2 in(2)" + assert.Equal( + t, + "select col1 from tb1 where cond1 in(?+) and cond2 in(?+)", + query.Fingerprint(q), + ) + q = "delete from db.table where col1 in(1) and col2=1" assert.Equal( t,