Skip to content

Commit b64c71e

Browse files
committed
Check uid ranges
Fixes #5647 Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <[email protected]> (github: LK4D4)
1 parent 5e76f74 commit b64c71e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

user/user.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ import (
99
"strings"
1010
)
1111

12+
const (
13+
minId = 0
14+
maxId = 1<<31 - 1 //for 32-bit systems compatibility
15+
)
16+
17+
var (
18+
ErrRange = fmt.Errorf("Uids and gids must be in range %d-%d", minId, maxId)
19+
)
20+
1221
type User struct {
1322
Name string
1423
Pass string
@@ -194,6 +203,9 @@ func GetUserGroupSupplementary(userSpec string, defaultUid int, defaultGid int)
194203
// not numeric - we have to bail
195204
return 0, 0, nil, fmt.Errorf("Unable to find user %v", userArg)
196205
}
206+
if uid < minId || uid > maxId {
207+
return 0, 0, nil, ErrRange
208+
}
197209

198210
// if userArg couldn't be found in /etc/passwd but is numeric, just roll with it - this is legit
199211
}
@@ -226,6 +238,9 @@ func GetUserGroupSupplementary(userSpec string, defaultUid int, defaultGid int)
226238
// not numeric - we have to bail
227239
return 0, 0, nil, fmt.Errorf("Unable to find group %v", groupArg)
228240
}
241+
if gid < minId || gid > maxId {
242+
return 0, 0, nil, ErrRange
243+
}
229244

230245
// if groupArg couldn't be found in /etc/group but is numeric, just roll with it - this is legit
231246
}

0 commit comments

Comments
 (0)