Skip to content

Commit

Permalink
sdk/java: limit generated uid/gid to int32 for sql engines (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored May 26, 2023
1 parent bc07047 commit cbeafb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sdk/java/libjfs/guid.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type mapping struct {
sync.Mutex
salt string
local bool
mask uint32
usernames map[string]uint32
userIDs map[uint32]string
groups map[string]uint32
Expand All @@ -55,7 +56,11 @@ func (m *mapping) genGuid(name string) uint32 {
digest := md5.Sum([]byte(m.salt + name + m.salt))
a := binary.LittleEndian.Uint64(digest[0:8])
b := binary.LittleEndian.Uint64(digest[8:16])
return uint32(a ^ b)
id := uint32(a ^ b)
if m.mask > 0 {
id &= m.mask
}
return id
}

func (m *mapping) lookupUser(name string) uint32 {
Expand Down
4 changes: 4 additions & 0 deletions sdk/java/libjfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func getOrCreate(name, user, group, superuser, supergroup string, f func() *fs.F
if jfs == nil {
return 0
}
switch jfs.Meta().Name() {
case "mysql", "postgres", "sqlite3":
m.mask = 0x7FFFFFFF // limit generated uid to int32
}
logger.Infof("JuiceFileSystem created for user:%s group:%s", user, group)
}
w := &wrapper{jfs, nil, m, user, superuser, supergroup}
Expand Down

0 comments on commit cbeafb7

Please sign in to comment.