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

sysvar: fix inconsistency in setting password validation sysvars #39584

Merged
merged 3 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 12 additions & 3 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ var defaultSysVars = []*SysVar{
return "", err
}
if minLength := numberCount + specialCharCount + 2*int32(mixedCaseCount); length < minLength {
PasswordValidationLength.Store(minLength)
err = updatePasswordValidationLength(vars, minLength)
if err != nil {
return "", err
}
}
return normalizedValue, nil
},
Expand All @@ -539,7 +542,10 @@ var defaultSysVars = []*SysVar{
return "", err
}
if minLength := int32(numberCount) + specialCharCount + 2*mixedCaseCount; length < minLength {
PasswordValidationLength.Store(minLength)
err = updatePasswordValidationLength(vars, minLength)
if err != nil {
return "", err
}
}
return normalizedValue, nil
},
Expand All @@ -558,7 +564,10 @@ var defaultSysVars = []*SysVar{
return "", err
}
if minLength := numberCount + int32(specialCharCount) + 2*mixedCaseCount; length < minLength {
PasswordValidationLength.Store(minLength)
err = updatePasswordValidationLength(vars, minLength)
if err != nil {
return "", err
}
}
return normalizedValue, nil
},
Expand Down
10 changes: 10 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package variable

import (
"context"
"fmt"
"io"
"strconv"
Expand Down Expand Up @@ -531,6 +532,15 @@ func collectAllowFuncName4ExpressionIndex() string {
return strings.Join(str, ", ")
}

func updatePasswordValidationLength(s *SessionVars, length int32) error {
err := s.GlobalVarsAccessor.SetGlobalSysVarOnly(context.Background(), ValidatePasswordLength, strconv.FormatInt(int64(length), 10))
if err != nil {
return err
}
PasswordValidationLength.Store(length)
return nil
}

// GAFunction4ExpressionIndex stores functions GA for expression index.
var GAFunction4ExpressionIndex = map[string]struct{}{
ast.Lower: {},
Expand Down