Merge pull request #2763 from zhsj/fix-32

Fix int overflow in test on 32 bit system
This commit is contained in:
Kir Kolyshkin
2021-01-27 11:37:33 -08:00
committed by GitHub
3 changed files with 5 additions and 15 deletions
+2 -2
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{}
+3 -8
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 {
-5
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))
}