Skip to content

fix: unexpected empty query cause operator panic #913

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions pkg/internal/mysql/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func CreateUserIfNotExists(ctx context.Context, sql SQLRunner,
}

if len(permissions) > 0 {
queries = append(queries, permissionsToQuery(permissions, user, allowedHosts))
query, err := permissionsToQuery(permissions, user, allowedHosts)
if err != nil {
return err
}
queries = append(queries, query)
}

query := BuildAtomicQuery(queries...)
Expand Down Expand Up @@ -114,11 +118,14 @@ func DropUser(ctx context.Context, sql SQLRunner, user, host string) error {
return nil
}

func permissionsToQuery(permissions []mysqlv1alpha1.MysqlPermission, user string, allowedHosts []string) Query {
func permissionsToQuery(permissions []mysqlv1alpha1.MysqlPermission, user string, allowedHosts []string) (Query, error) {
permQueries := []Query{}

for _, perm := range permissions {
// If you wish to grant permissions on all tables, you should explicitly use "*"
if perm.Tables == nil || len(perm.Tables) == 0 {
return Query{}, fmt.Errorf("empty table name in permission %+v, if you wish to grant permissions on all tables, you should explicitly use \"*\"", perm)
}
for _, table := range perm.Tables {
args := []interface{}{}

Expand All @@ -139,7 +146,7 @@ func permissionsToQuery(permissions []mysqlv1alpha1.MysqlPermission, user string
}
}

return ConcatenateQueries(permQueries...)
return ConcatenateQueries(permQueries...), nil
}

func escapeID(id string) string {
Expand Down