Skip to content

Commit

Permalink
sessionctx/variable: fix panic when set variable='' (#9533) (#9539)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and shenli committed Mar 4, 2019
1 parent e811eb7 commit 3d40d25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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"
Expand Down Expand Up @@ -3464,6 +3465,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.GenWithStackByArgs("max_user_connections").Error())
}

func (s *testIntegrationSuite) TestIssues(c *C) {
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,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 {
Expand Down

0 comments on commit 3d40d25

Please sign in to comment.