Fix simple mistakes identified by goreportcard.

These are primarily simplification and lint mistakes. However, minor
fixes are also included and tests added where appropriate.

PiperOrigin-RevId: 351425971
This commit is contained in:
Adin Scannell
2021-01-12 12:38:22 -08:00
committed by gVisor bot
parent a20da70829
commit 4e03e87547
63 changed files with 293 additions and 201 deletions
+1
View File
@@ -14,6 +14,7 @@
package linux
// Fadvise constants.
const (
POSIX_FADV_NORMAL = 0
POSIX_FADV_RANDOM = 1
+10 -4
View File
@@ -14,8 +14,9 @@
package linux
// Control commands used with semctl, shmctl, and msgctl. Source:
// include/uapi/linux/ipc.h.
// Control commands used with semctl, shmctl, and msgctl.
//
// Source: include/uapi/linux/ipc.h.
const (
IPC_RMID = 0
IPC_SET = 1
@@ -23,14 +24,19 @@ const (
IPC_INFO = 3
)
// resource get request flags. Source: include/uapi/linux/ipc.h
// Resource get request flags.
//
// Source: include/uapi/linux/ipc.h
const (
IPC_CREAT = 00001000
IPC_EXCL = 00002000
IPC_NOWAIT = 00004000
)
const IPC_PRIVATE = 0
// IPC flags.
const (
IPC_PRIVATE = 0
)
// In Linux, amd64 does not enable CONFIG_ARCH_WANT_IPC_PARSE_VERSION, so SysV
// IPC unconditionally uses the "new" 64-bit structures that are needed for
+1
View File
@@ -288,6 +288,7 @@ type IP6TIP struct {
_ [3]byte
}
// SizeOfIP6TIP is the size of an IP6 header.
const SizeOfIP6TIP = 136
// Flags in IP6TIP.Flags. Corresponding constants are in
+1
View File
@@ -29,6 +29,7 @@ const (
SCHED_RESET_ON_FORK = 0x40000000
)
// Scheduling priority group selectors.
const (
PRIO_PGRP = 0x1
PRIO_PROCESS = 0x0
+2
View File
@@ -30,8 +30,10 @@ const (
SECCOMP_GET_ACTION_AVAIL = 2
)
// BPFAction is an action for a BPF filter.
type BPFAction uint32
// BPFAction definitions.
const (
SECCOMP_RET_KILL_PROCESS BPFAction = 0x80000000
SECCOMP_RET_KILL_THREAD BPFAction = 0x00000000
+4 -1
View File
@@ -49,7 +49,10 @@ const (
SEMUSZ = 20
)
const SEM_UNDO = 0x1000
// Semaphore flags.
const (
SEM_UNDO = 0x1000
)
// Sembuf is equivalent to struct sembuf.
//
+2 -2
View File
@@ -267,7 +267,7 @@ func (fs *FeatureSet) UseXsave() bool {
// FlagsString prints out supported CPU "flags" field in /proc/cpuinfo.
func (fs *FeatureSet) FlagsString() string {
var s []string
for f, _ := range arm64FeatureStrings {
for f := range arm64FeatureStrings {
if fs.Set[f] {
if fstr := f.flagString(); fstr != "" {
s = append(s, fstr)
@@ -296,7 +296,7 @@ func (fs FeatureSet) WriteCPUInfoTo(cpu uint, b *bytes.Buffer) {
func HostFeatureSet() *FeatureSet {
s := make(map[Feature]bool)
for f, _ := range arm64FeatureStrings {
for f := range arm64FeatureStrings {
if hwCap&(1<<f) != 0 {
s[f] = true
}
+1 -1
View File
@@ -241,7 +241,7 @@ func (c *Client) watch(socket *unet.Socket) {
defer c.closedWg.Done()
events := []unix.PollFd{
unix.PollFd{
{
Fd: int32(socket.FD()),
Events: unix.POLLHUP | unix.POLLRDHUP,
},
+2 -2
View File
@@ -61,7 +61,7 @@ func Install(rules SyscallRules) error {
log.Infof("Installing seccomp filters for %d syscalls (action=%v)", len(rules), defaultAction)
instrs, err := BuildProgram([]RuleSet{
RuleSet{
{
Rules: rules,
Action: linux.SECCOMP_RET_ALLOW,
},
@@ -160,7 +160,7 @@ func buildIndex(rules []RuleSet, program *bpf.ProgramBuilder) error {
}
}
syscalls := make([]uintptr, 0, len(requiredSyscalls))
for sysno, _ := range requiredSyscalls {
for sysno := range requiredSyscalls {
syscalls = append(syscalls, sysno)
}
sort.Slice(syscalls, func(i, j int) bool { return syscalls[i] < syscalls[j] })
+1 -1
View File
@@ -932,7 +932,7 @@ func TestRandom(t *testing.T) {
t.Logf("Testing filters: %v", syscallRules)
instrs, err := BuildProgram([]RuleSet{
RuleSet{
{
Rules: syscallRules,
Action: linux.SECCOMP_RET_ALLOW,
},
+3 -3
View File
@@ -1680,8 +1680,8 @@ type SegmentDataSlices struct {
Values []Value
}
// ExportSortedSlice returns a copy of all segments in the given set, in ascending
// key order.
// ExportSortedSlices returns a copy of all segments in the given set, in
// ascending key order.
func (s *Set) ExportSortedSlices() *SegmentDataSlices {
var sds SegmentDataSlices
for seg := s.FirstSegment(); seg.Ok(); seg = seg.NextSegment() {
@@ -1695,7 +1695,7 @@ func (s *Set) ExportSortedSlices() *SegmentDataSlices {
return &sds
}
// ImportSortedSlice initializes the given set from the given slice.
// ImportSortedSlices initializes the given set from the given slice.
//
// Preconditions:
// * s must be empty.
+1
View File
@@ -510,6 +510,7 @@ func (InodeDenyWriteChecker) Check(ctx context.Context, inode *fs.Inode, p fs.Pe
//InodeNotAllocatable can be used by Inodes that do not support Allocate().
type InodeNotAllocatable struct{}
// Allocate implements fs.InodeOperations.Allocate.
func (InodeNotAllocatable) Allocate(_ context.Context, _ *fs.Inode, _, _ int64) error {
return syserror.EOPNOTSUPP
}
+1
View File
@@ -367,6 +367,7 @@ func (i *Inode) Truncate(ctx context.Context, d *Dirent, size int64) error {
return i.InodeOperations.Truncate(ctx, i, size)
}
// Allocate calls i.InodeOperations.Allocate with i as the Inode.
func (i *Inode) Allocate(ctx context.Context, d *Dirent, offset int64, length int64) error {
if i.overlay != nil {
return overlayAllocate(ctx, i.overlay, d, offset, length)
+1 -1
View File
@@ -114,7 +114,7 @@ func Boot() (*kernel.Kernel, error) {
return nil, err
}
tg := k.NewThreadGroup(nil, k.RootPIDNamespace(), kernel.NewSignalHandlers(), linux.SIGCHLD, ls)
k.TestOnly_SetGlobalInit(tg)
k.TestOnlySetGlobalInit(tg)
return k, nil
}
+12 -2
View File
@@ -62,18 +62,28 @@ const (
// field is displayed as 4294967295 (-1 as an unsigned integer);" -
// user_namespaces(7)
OverflowUID = UID(65534)
// OverflowGID is the group equivalent to OverflowUID.
OverflowGID = GID(65534)
// NobodyKUID is the user ID usually reserved for the least privileged user
// "nobody".
NobodyKUID = KUID(65534)
// NobodyKGID is the group equivalent to NobodyKUID.
NobodyKGID = KGID(65534)
// RootKUID is the user ID usually used for the most privileged user "root".
RootKUID = KUID(0)
// RootKGID is the group equivalent to RootKUID.
RootKGID = KGID(0)
RootUID = UID(0)
RootGID = GID(0)
// RootUID is the root user.
RootUID = UID(0)
// RootGID is the root group.
RootGID = GID(0)
)
// Ok returns true if uid is not -1.
+2 -2
View File
@@ -1433,8 +1433,8 @@ func (k *Kernel) GlobalInit() *ThreadGroup {
return k.globalInit
}
// TestOnly_SetGlobalInit sets the thread group with ID 1 in the root PID namespace.
func (k *Kernel) TestOnly_SetGlobalInit(tg *ThreadGroup) {
// TestOnlySetGlobalInit sets the thread group with ID 1 in the root PID namespace.
func (k *Kernel) TestOnlySetGlobalInit(tg *ThreadGroup) {
k.globalInit = tg
}
@@ -65,6 +65,7 @@ func (k *Kernel) init(maxCPUs int) {
}
}
// EntryRegions returns the set of kernel entry regions (must be mapped).
func (k *Kernel) EntryRegions() map[uintptr]uintptr {
regions := make(map[uintptr]uintptr)
+1 -1
View File
@@ -205,7 +205,7 @@ func SetEntries(stk *stack.Stack, optVal []byte, ipv6 bool) *syserr.Error {
// Go through the list of supported hooks for this table and, for each
// one, set the rule it corresponds to.
for hook, _ := range replace.HookEntry {
for hook := range replace.HookEntry {
if table.ValidHooks()&(1<<hook) != 0 {
hk := hookFromLinux(hook)
table.BuiltinChains[hk] = stack.HookUnset
@@ -96,6 +96,7 @@ func (ownerMarshaler) unmarshal(buf []byte, filter stack.IPHeaderFilter) (stack.
return &owner, nil
}
// OwnerMatcher matches against a UID and/or GID.
type OwnerMatcher struct {
uid uint32
gid uint32
+1 -1
View File
@@ -471,7 +471,7 @@ func (s *socketOpsCommon) SendMsg(t *kernel.Task, src usermem.IOSequence, to []b
if len(to) > 0 {
switch s.stype {
case linux.SOCK_SEQPACKET:
to = nil
// to is ignored.
case linux.SOCK_STREAM:
if s.State() == linux.SS_CONNECTED {
return 0, syserr.ErrAlreadyConnected

Some files were not shown because too many files have changed in this diff Show More