Skip to content

Commit

Permalink
Fix int overflow in test on 32 bit system
Browse files Browse the repository at this point in the history
Signed-off-by: Shengjing Zhu <zhsj@debian.org>
  • Loading branch information
zhsj authored and kolyshkin committed Jan 26, 2021
1 parent be30b6e commit 00354e3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions libcontainer/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,15 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
// we asked for a group but didn't find it. let's check to see
// if we wanted a numeric group
if !found {
gid, err := strconv.Atoi(ag)
gid, err := strconv.ParseInt(ag, 10, 64)
if err != nil {
return nil, fmt.Errorf("Unable to find group %s", ag)
}
// Ensure gid is inside gid range.
if gid < minId || gid > maxId {
return nil, ErrRange
}
gidMap[gid] = struct{}{}
gidMap[int(gid)] = struct{}{}
}
}
gids := []int{}
Expand Down
11 changes: 3 additions & 8 deletions libcontainer/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strconv"
"strings"
"testing"

"github.com/opencontainers/runc/libcontainer/utils"
)

func TestUserParseLine(t *testing.T) {
Expand Down Expand Up @@ -440,15 +438,12 @@ this is just some garbage data
expected: nil,
hasError: true,
},
}

if utils.GetIntSize() > 4 {
tests = append(tests, foo{
{
// groups with too large id
groups: []string{strconv.Itoa(1 << 31)},
groups: []string{strconv.FormatInt(1<<31, 10)},
expected: nil,
hasError: true,
})
},
}

for _, test := range tests {
Expand Down
5 changes: 0 additions & 5 deletions libcontainer/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"strings"
"unsafe"

"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -106,7 +105,3 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
}
return
}

func GetIntSize() int {
return int(unsafe.Sizeof(1))
}

0 comments on commit 00354e3

Please sign in to comment.