From 02236014af8b7383e81d7d40effefe72eb6f0654 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 4 Mar 2019 10:42:30 +0800 Subject: [PATCH] sessionctx/variable: fix panic when set variable='' --- expression/integration_test.go | 8 ++++++++ sessionctx/variable/varsutil.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index aa2f73cbd2184..e1dd81db6e369 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -33,6 +33,7 @@ import ( plannercore "github.com/pingcap/tidb/planner/core" "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/types" @@ -3594,6 +3595,13 @@ func (s *testIntegrationSuite) TestSetVariables(c *C) { c.Assert(err, IsNil) 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.GenWithStackByArgs("max_user_connections").Error()) + _, err = tk.Exec("set @@global.max_prepared_stmt_count='';") + c.Assert(err, NotNil) + c.Assert(err.Error(), Equals, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error()) } func (s *testIntegrationSuite) TestIssues(c *C) { diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 7c0887577de54..563681749f54d 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -206,6 +206,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.GenWithStackByArgs(name) + } if value[0] == '-' { _, err := strconv.ParseInt(value, 10, 64) if err != nil {