Skip to content

Commit 3eaa125

Browse files
committed
1 parent 73d29c6 commit 3eaa125

File tree

549 files changed

+70
-288962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

549 files changed

+70
-288962
lines changed

go.mod

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/TarmoKople/go-mysql
2+
3+
go 1.17
4+
5+
require (
6+
github.com/percona/go-mysql v0.0.0-20210427141028-73d29c6da78c
7+
github.com/pkg/errors v0.8.1
8+
github.com/shirou/gopsutil v0.0.0-20190323131628-2cbc9195c892
9+
github.com/stretchr/testify v1.3.0
10+
)
11+
12+
require (
13+
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/go-ole/go-ole v1.2.4 // indirect
16+
github.com/pmezard/go-difflib v1.0.0 // indirect
17+
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
18+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
19+
)

go.sum

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
2+
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
7+
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
8+
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
9+
github.com/percona/go-mysql v0.0.0-20210427141028-73d29c6da78c h1:1SZ7nS+kSaO63IpaKspf/gf8602QcgP2eXNPMNOIc0M=
10+
github.com/percona/go-mysql v0.0.0-20210427141028-73d29c6da78c/go.mod h1:/SGLf9OMxlnK6jq4mkFiImBcJXXk5jwD+lDrwDaGXcw=
11+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
12+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/shirou/gopsutil v0.0.0-20190323131628-2cbc9195c892 h1:oiNB/s36DdNBEnulbhdj6zHS73U/wRQihnsoJwanqfM=
16+
github.com/shirou/gopsutil v0.0.0-20190323131628-2cbc9195c892/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc=
17+
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
18+
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
19+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
20+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
21+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
22+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
23+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
24+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
25+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

query/query.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ func Fingerprint(q string) string {
170170
if Debug {
171171
fmt.Printf("\n%d:%d %s/%s [%d:%d] %x %q\n", qi, fi, stateName[s], stateName[sqlState], cpFromOffset, cpToOffset, r, r)
172172
}
173-
173+
// check `fi` overflow
174+
if fi >= len(f) {
175+
break
176+
}
174177
/**
175178
* 1. Skip parts of the query for certain states.
176179
*/
@@ -379,6 +382,9 @@ func Fingerprint(q string) string {
379382
valueNo++
380383
if valueNo == 1 {
381384
if qi-firstPar > 1 {
385+
if qi-firstPar == 2 {
386+
f = append(f, 0)
387+
}
382388
copy(f[fi:fi+4], "(?+)")
383389
fi += 4
384390
} else {

query/query_test.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535

3636
"github.com/stretchr/testify/assert"
3737

38-
"github.com/percona/go-mysql/query"
39-
_ "github.com/percona/go-mysql/test"
38+
"github.com/TarmoKople/go-mysql/query"
39+
_ "github.com/TarmoKople/go-mysql/test"
4040
)
4141

4242
func TestFingerprintBasic(t *testing.T) {
@@ -556,6 +556,14 @@ func TestFingerprintPanicChallenge2(t *testing.T) {
556556
"select ? ? ? ? from kamil",
557557
query.Fingerprint(q),
558558
)
559+
560+
q = "select col1 from tb1 where cond1 in(1) and cond2 in(2)"
561+
assert.Equal(
562+
t,
563+
"select col1 from tb1 where cond1 in(?+) and cond2 in(?+)",
564+
query.Fingerprint(q),
565+
)
566+
559567
}
560568

561569
func TestFingerprintDashesInNames(t *testing.T) {
@@ -649,4 +657,13 @@ func TestFingerprintWithNumberInDbName(t *testing.T) {
649657
"select 123foo from 123foo",
650658
query.Fingerprint(q),
651659
)
660+
661+
// fix fi overflow cause index out of range panic
662+
q = "insert into tb values(1)"
663+
assert.Equal(
664+
t,
665+
"insert into tb values(?+)",
666+
query.Fingerprint(q),
667+
)
668+
652669
}

vendor/github.com/StackExchange/wmi/LICENSE

-20
This file was deleted.

vendor/github.com/StackExchange/wmi/swbemservices.go

-260
This file was deleted.

0 commit comments

Comments
 (0)