Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ linters:
gosec:
excludes:
- G104 # G104: Errors unhandled; (TODO: reduce unhandled errors, or explicitly ignore)
- G115 # G115: integer overflow conversion; (TODO: verify these: https://github.com/docker/cli/issues/5584)
- G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions)
- G307 # G307: Deferring unsafe method "*os.File" on type "Close" (also EXC0008); (TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close")

Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func copyProgress(ctx context.Context, dst io.Writer, header string, total *int6
}

// Write to the buffer first to avoid flickering and context switching
fmt.Fprint(buf, aec.Column(uint(len(header)+1)))
fmt.Fprint(buf, aec.Column(uint(len(header)+1))) //nolint:gosec // G115: len() is always non-negative, safe to convert to uint
fmt.Fprint(buf, aec.EraseLine(aec.EraseModes.Tail))
fmt.Fprint(buf, progressHumanSize(n))

Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
BlkioDeviceReadIOps: copts.deviceReadIOps.GetList(),
BlkioDeviceWriteIOps: copts.deviceWriteIOps.GetList(),
IOMaximumIOps: copts.ioMaxIOps,
IOMaximumBandwidth: uint64(copts.ioMaxBandwidth),
IOMaximumBandwidth: uint64(copts.ioMaxBandwidth), //nolint:gosec // G115: ioMaxBandwidth is validated to be non-negative
Ulimits: copts.ulimits.GetList(),
DeviceCgroupRules: copts.deviceCgroupRules.GetSlice(),
Comment on lines 636 to 640
Devices: deviceMappings,
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/stats_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func calculateCPUPercentUnix(previousCPU container.CPUStats, curCPUStats contain

func calculateCPUPercentWindows(v *container.StatsResponse) float64 {
// Max number of 100ns intervals between the previous time read and now
possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals
possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) //nolint:gosec // G115: time difference between CPU stat reads is always positive
possIntervals /= 100 // Convert to number of 100ns intervals
possIntervals *= uint64(v.NumProcs) // Multiply by the number of processors

Comment on lines +188 to 191
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func printImageTree(outs command.Streams, view treeView) {
// available for image names and removes any columns that would be too narrow
// to display their content.
func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn {
nameWidth := int(width)
nameWidth := int(width) //nolint:gosec // G115: terminal width is a small value well within int range
if nameWidth > 0 {
for idx, h := range columns {
if h.Width == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/service/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, opts *logsOptions) erro
if service.Service.Spec.Mode.Replicated != nil && service.Service.Spec.Mode.Replicated.Replicas != nil {
// if replicas are initialized, figure out if we need to pad them
replicas := *service.Service.Spec.Mode.Replicated.Replicas
maxLength = getMaxLength(int(replicas))
maxLength = getMaxLength(int(replicas)) //nolint:gosec // G115: replica count is far below math.MaxInt in practice
}

// we can't prettify tty logs. tell the user that this is the case.
Expand Down
10 changes: 5 additions & 5 deletions cli/command/service/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.
u.slotMap = make(map[int]int)

// Draw progress bars in order
writeOverallProgress(u.progressOut, 0, int(replicas), rollback)
writeOverallProgress(u.progressOut, 0, int(replicas), rollback) //nolint:gosec // G115: replica count is far below math.MaxInt in practice

if replicas <= maxProgressBars {
Comment on lines 303 to 306
for i := uint64(1); i <= replicas; i++ {
Expand Down Expand Up @@ -340,7 +340,7 @@ func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.
}

if !u.done {
writeOverallProgress(u.progressOut, int(running), int(replicas), rollback)
writeOverallProgress(u.progressOut, int(running), int(replicas), rollback) //nolint:gosec // G115: running/replica counts are far below math.MaxInt in practice

if running == replicas {
Comment on lines 342 to 345
u.done = true
Expand Down Expand Up @@ -383,7 +383,7 @@ func (*replicatedProgressUpdater) tasksBySlot(tasks []swarm.Task, activeNodes ma
}

func (u *replicatedProgressUpdater) writeTaskProgress(task swarm.Task, mappedSlot int, replicas uint64) {
if u.done || replicas > maxProgressBars || uint64(mappedSlot) > replicas {
if u.done || replicas > maxProgressBars || uint64(mappedSlot) > replicas { //nolint:gosec // G115: mappedSlot is a positive task slot number, safe to convert to uint64
return
}

Expand Down Expand Up @@ -572,8 +572,8 @@ type replicatedJobProgressUpdater struct {
}

func newReplicatedJobProgressUpdater(service swarm.Service, progressOut progress.Output) *replicatedJobProgressUpdater {
concurrent := int(*service.Spec.Mode.ReplicatedJob.MaxConcurrent)
total := int(*service.Spec.Mode.ReplicatedJob.TotalCompletions)
concurrent := int(*service.Spec.Mode.ReplicatedJob.MaxConcurrent) //nolint:gosec // G115: job concurrency count is far below math.MaxInt in practice
total := int(*service.Spec.Mode.ReplicatedJob.TotalCompletions) //nolint:gosec // G115: job total completions count is far below math.MaxInt in practice
Comment on lines 574 to +576

return &replicatedJobProgressUpdater{
progressOut: progressOut,
Expand Down
4 changes: 2 additions & 2 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
startInterval = time.Duration(*healthcheck.StartInterval)
}
if healthcheck.Retries != nil {
retries = int(*healthcheck.Retries)
retries = int(*healthcheck.Retries) //nolint:gosec // G115: healthcheck retry count is a small value, safe to convert
}
Comment on lines 462 to 464
return &container.HealthConfig{
Test: healthcheck.Test,
Expand All @@ -487,7 +487,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
Condition: swarm.RestartPolicyConditionAny,
}, nil
case policy.IsOnFailure():
attempts := uint64(policy.MaximumRetryCount)
attempts := uint64(policy.MaximumRetryCount) //nolint:gosec // G115: MaximumRetryCount is a non-negative value, safe to convert
return &swarm.RestartPolicy{
Condition: swarm.RestartPolicyConditionOnFailure,
MaxAttempts: &attempts,
Expand Down
8 changes: 4 additions & 4 deletions opts/swarmopts/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p *PortOpt) Set(value string) error {
return fmt.Errorf("invalid target port (%s): value must be an integer: %w", val, err)
}

pConfig.TargetPort = uint32(tPort)
pConfig.TargetPort = uint32(tPort) //nolint:gosec // G115: port numbers are in range [0, 65535], within uint32 bounds
case portOptPublishedPort:
pPort, err := strconv.ParseUint(val, 10, 16)
if err != nil {
Expand All @@ -91,7 +91,7 @@ func (p *PortOpt) Set(value string) error {
return fmt.Errorf("invalid published port (%s): value must be an integer: %w", val, err)
}

pConfig.PublishedPort = uint32(pPort)
pConfig.PublishedPort = uint32(pPort) //nolint:gosec // G115: port numbers are in range [0, 65535], within uint32 bounds
default:
return fmt.Errorf("invalid field key: %s", key)
}
Expand Down Expand Up @@ -176,8 +176,8 @@ func ConvertPortToPortConfig(
ports = append(ports, swarm.PortConfig{
// TODO Name: ?
Protocol: portProto.Proto(),
TargetPort: uint32(portProto.Num()),
PublishedPort: uint32(p.Num()),
TargetPort: uint32(portProto.Num()), //nolint:gosec // G115: port numbers are in range [0, 65535], within uint32 bounds
PublishedPort: uint32(p.Num()), //nolint:gosec // G115: port numbers are in range [0, 65535], within uint32 bounds
PublishMode: swarm.PortConfigPublishModeIngress,
})
}
Expand Down
Loading