Skip to content

Commit 3d40d25

Browse files
crazycs520shenli
authored andcommitted
sessionctx/variable: fix panic when set variable='' (#9533) (#9539)
1 parent e811eb7 commit 3d40d25

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
@@ -32,6 +32,7 @@ import (
3232
plannercore "github.com/pingcap/tidb/planner/core"
3333
"github.com/pingcap/tidb/session"
3434
"github.com/pingcap/tidb/sessionctx"
35+
"github.com/pingcap/tidb/sessionctx/variable"
3536
"github.com/pingcap/tidb/store/mockstore"
3637
"github.com/pingcap/tidb/table"
3738
"github.com/pingcap/tidb/types"
@@ -3464,6 +3465,10 @@ func (s *testIntegrationSuite) TestSetVariables(c *C) {
34643465
_, err = tk.Exec("set global transaction read write;")
34653466
r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`)
34663467
r.Check(testkit.Rows("0 0 0 0"))
3468+
3469+
_, err = tk.Exec("set @@global.max_user_connections='';")
3470+
c.Assert(err, NotNil)
3471+
c.Assert(err.Error(), Equals, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error())
34673472
}
34683473

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

sessionctx/variable/varsutil.go

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

194194
func checkUInt64SystemVar(name, value string, min, max uint64, vars *SessionVars) (string, error) {
195+
if len(value) == 0 {
196+
return value, ErrWrongTypeForVar.GenWithStackByArgs(name)
197+
}
195198
if value[0] == '-' {
196199
_, err := strconv.ParseInt(value, 10, 64)
197200
if err != nil {

0 commit comments

Comments
 (0)