Skip to content

Commit

Permalink
Merge pull request #161 from YenchangChan/main
Browse files Browse the repository at this point in the history
fix:panic error when decode password
  • Loading branch information
YenchangChan authored Oct 31, 2021
2 parents df1b5a4 + a6abcd7 commit 4e049cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 10 additions & 2 deletions repository/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ func DecodePasswd(conf *model.CKManClickHouseConfig) {
if conf.SshPassword != "" {
conf.SshPassword = common.AesDecryptECB(conf.SshPassword)
}
for idx, user := range conf.UsersConf.Users {
var users []model.User
/*
conf.UsersConf.Users and lp.Data.Clusters[key] pointer the same address when policy is local
When conf changed, lp.Data will changed,too. which will cause panic when decode password (runtime error: slice bounds out of range [:16] with capacity 3)
That's not allow to happen, So we need another memory to storage users, to ensure that the original data (lp.Data) not changed when decode password
*/
for _, user := range conf.UsersConf.Users {
if user.Password != "" {
conf.UsersConf.Users[idx].Password = common.AesDecryptECB(user.Password)
user.Password = common.AesDecryptECB(user.Password)
users = append(users, user)
}
}
conf.UsersConf.Users = users
}
4 changes: 1 addition & 3 deletions repository/local/local.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package local

import (
"encoding/json"
"fmt"
"github.com/housepower/ckman/common"
"github.com/housepower/ckman/log"
"github.com/housepower/ckman/model"
"github.com/housepower/ckman/repository"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
"os"
"path"
"sync"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type LocalPersistent struct {
Config LocalConfig
InTransAction bool
Expand Down

0 comments on commit 4e049cb

Please sign in to comment.