Skip to content

Commit 6019c89

Browse files
committed
sessionctx/variable: fix panic when set variable='' (pingcap#9533)
1 parent b6a0381 commit 6019c89

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

expression/integration_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/pingcap/tidb/plan"
3131
"github.com/pingcap/tidb/session"
3232
"github.com/pingcap/tidb/sessionctx"
33+
"github.com/pingcap/tidb/sessionctx/variable"
3334
"github.com/pingcap/tidb/store/mockstore"
3435
"github.com/pingcap/tidb/table"
3536
"github.com/pingcap/tidb/terror"
@@ -3225,6 +3226,10 @@ func (s *testIntegrationSuite) TestSetVariables(c *C) {
32253226
_, err = tk.Exec("set global transaction read write;")
32263227
r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`)
32273228
r.Check(testkit.Rows("0 0 0 0"))
3229+
3230+
_, err = tk.Exec("set @@global.max_user_connections='';")
3231+
c.Assert(err, NotNil)
3232+
c.Assert(err.Error(), Equals, variable.ErrWrongTypeForVar.GenByArgs("max_user_connections").Error())
32283233
}
32293234

32303235
func (s *testIntegrationSuite) TestIssues(c *C) {

sessionctx/variable/varsutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ func ValidateGetSystemVar(name string, isGlobal bool) error {
169169
}
170170

171171
func checkUInt64SystemVar(name, value string, min, max uint64, vars *SessionVars) (string, error) {
172+
if len(value) == 0 {
173+
return value, ErrWrongTypeForVar.GenByArgs(name)
174+
}
172175
if value[0] == '-' {
173176
_, err := strconv.ParseInt(value, 10, 64)
174177
if err != nil {

0 commit comments

Comments
 (0)