Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner/core,session: fix privilege check for update (8376) #10439

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ func (b *planBuilder) buildUpdate(update *ast.UpdateStmt) (Plan, error) {
if dbName == "" {
dbName = b.ctx.GetSessionVars().CurrentDB
}
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.UpdatePriv, dbName, t.Name.L, "")
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SelectPriv, dbName, t.Name.L, "")
}

if sel.Where != nil {
Expand Down
26 changes: 25 additions & 1 deletion session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package session_test

import (
"fmt"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -2350,6 +2351,29 @@ func (s *testSessionSuite) TestSetGroupConcatMaxLen(c *C) {

func (s *testSessionSuite) TestUpdatePrivilege(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t1, t2;")
tk.MustExec("create table t1 (id int);")
tk.MustExec("create table t2 (id int);")
tk.MustExec("insert into t1 values (1);")
tk.MustExec("insert into t2 values (2);")
tk.MustExec("create user xxx;")
tk.MustExec("grant all on test.t1 to xxx;")
tk.MustExec("grant select on test.t2 to xxx;")
tk.MustExec("flush privileges;")

tk1 := testkit.NewTestKitWithInit(c, s.store)
c.Assert(tk1.Se.Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"},
[]byte(""),
[]byte("")), IsTrue)

_, err := tk1.Exec("update t2 set id = 666 where id = 1;")
c.Assert(err, NotNil)
c.Assert(strings.Contains(err.Error(), "privilege check fail"), IsTrue)

// Cover a bug that t1 and t2 both require update privilege.
// In fact, the privlege check for t1 should be update, and for t2 should be select.
_, err = tk1.Exec("update t1,t2 set t1.id = t2.id;")
c.Assert(err, IsNil)

// Fix issue 8911
tk.MustExec("create database weperk")
Expand All @@ -2359,7 +2383,6 @@ func (s *testSessionSuite) TestUpdatePrivilege(c *C) {
tk.MustExec("grant all privileges on weperk.* to 'weperk'@'%'")
tk.MustExec("flush privileges;")

tk1 := testkit.NewTestKitWithInit(c, s.store)
c.Assert(tk1.Se.Auth(&auth.UserIdentity{Username: "weperk", Hostname: "%"},
[]byte(""), []byte("")), IsTrue)
tk1.MustExec("use weperk")
Expand Down Expand Up @@ -2387,6 +2410,7 @@ WHERE
s.a = t.a
and t.c >= 1 and t.c <= 10000
and s.b !='xx';`)

}

func (s *testSessionSuite) TestTxnGoString(c *C) {
Expand Down