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
// 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)
}
@@ -474,7 +474,7 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
if gid < minId || gid > maxId {
return nil, ErrRange
}
gidMap[gid] = struct{}{}
gidMap[int(gid)] = struct{}{}
}
}
gids := []int{}

View File

@@ -7,8 +7,6 @@ import (
"strconv"
"strings"
"testing"
"github.com/opencontainers/runc/libcontainer/utils"
)
func TestUserParseLine(t *testing.T) {
@@ -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 {

View File

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