From 6019c89b63a5fc4173ec0636a1de27f6ce7167cd Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 4 Mar 2019 17:33:06 +0800 Subject: [PATCH] sessionctx/variable: fix panic when set variable='' (#9533) --- expression/integration_test.go | 5 +++++ sessionctx/variable/varsutil.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index 71595d8633232..1d6613f7244f2 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -30,6 +30,7 @@ import ( "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/terror" @@ -3225,6 +3226,10 @@ func (s *testIntegrationSuite) TestSetVariables(c *C) { _, err = tk.Exec("set global transaction read write;") r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) r.Check(testkit.Rows("0 0 0 0")) + + _, err = tk.Exec("set @@global.max_user_connections='';") + c.Assert(err, NotNil) + c.Assert(err.Error(), Equals, variable.ErrWrongTypeForVar.GenByArgs("max_user_connections").Error()) } func (s *testIntegrationSuite) TestIssues(c *C) { diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index de0b094293a2b..8d1dd7fa7d1a1 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -169,6 +169,9 @@ func ValidateGetSystemVar(name string, isGlobal bool) error { } func checkUInt64SystemVar(name, value string, min, max uint64, vars *SessionVars) (string, error) { + if len(value) == 0 { + return value, ErrWrongTypeForVar.GenByArgs(name) + } if value[0] == '-' { _, err := strconv.ParseInt(value, 10, 64) if err != nil {