Fix int overflow in test on 32 bit system

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
This commit is contained in:
Shengjing Zhu
2021-01-23 22:53:32 +08:00
parent c69ae759fb
commit f4d153b086
3 changed files with 5 additions and 15 deletions

View File

@@ -466,7 +466,7 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
// we asked for a group but didn't find it. let's check to see // we asked for a group but didn't find it. let's check to see
// if we wanted a numeric group // if we wanted a numeric group
if !found { if !found {
gid, err := strconv.Atoi(ag) gid, err := strconv.ParseInt(ag, 10, 64)
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to find group %s", ag) return nil, fmt.Errorf("Unable to find group %s", ag)
} }
@@ -474,7 +474,7 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
if gid < minId || gid > maxId { if gid < minId || gid > maxId {
return nil, ErrRange return nil, ErrRange
} }
gidMap[gid] = struct{}{} gidMap[int(gid)] = struct{}{}
} }
} }
gids := []int{} gids := []int{}

View File

@@ -7,8 +7,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"github.com/opencontainers/runc/libcontainer/utils"
) )
func TestUserParseLine(t *testing.T) { func TestUserParseLine(t *testing.T) {
@@ -440,15 +438,12 @@ this is just some garbage data
expected: nil, expected: nil,
hasError: true, hasError: true,
}, },
} {
if utils.GetIntSize() > 4 {
tests = append(tests, foo{
// groups with too large id // groups with too large id
groups: []string{strconv.Itoa(1 << 31)}, groups: []string{strconv.FormatInt(1<<31, 10)},
expected: nil, expected: nil,
hasError: true, hasError: true,
}) },
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -6,7 +6,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@@ -106,7 +105,3 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
} }
return return
} }
func GetIntSize() int {
return int(unsafe.Sizeof(1))
}