lint: Clean up golangci-lint v1.60 complaints

This cleans up the linting results by adding checks for
integer underflow/overflow in several places, suppressing the error in
places where it has been checked, or fixing the types when possible.
This commit is contained in:
Brian C. Lane 2025-02-13 16:49:40 -08:00 committed by Brian C. Lane
parent 2dad1a965e
commit 0256e09031
11 changed files with 47 additions and 12 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"time"
"github.com/BurntSushi/toml"
"github.com/osbuild/osbuild-composer/internal/upload/azure"
@ -20,7 +21,7 @@ type kerberosConfig struct {
type kojiServerConfig struct {
Kerberos *kerberosConfig `toml:"kerberos,omitempty"`
RelaxTimeoutFactor uint `toml:"relax_timeout_factor"`
RelaxTimeoutFactor time.Duration `toml:"relax_timeout_factor"`
}
type gcpConfig struct {

View file

@ -28,7 +28,7 @@ func (impl *FileResolveJobImpl) Run(job worker.Job) error {
}
}
if result.Results == nil || len(result.Results) == 0 {
if len(result.Results) == 0 {
logWithId.Infof("Resolving file contents failed: %v", err)
result.JobError = clienterrors.New(
clienterrors.ErrorRemoteFileResolution,

View file

@ -2,6 +2,7 @@ package main
import (
"fmt"
"math"
"net/url"
"time"
@ -102,7 +103,14 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
// Fail the Koji build if the job error is set and the necessary
// information to identify the job are available.
if kojiFinalizeJobResult.JobError != nil && initArgs != nil {
err = impl.kojiFail(args.Server, int(initArgs.BuildID), initArgs.Token)
/* #nosec G115 */
buildID := int(initArgs.BuildID)
// Make sure that signed integer conversion didn't underflow
if buildID < 0 {
logWithId.Errorf("BuildID integer underflow: %d", initArgs.BuildID)
return
}
err = impl.kojiFail(args.Server, buildID, initArgs.Token)
if err != nil {
logWithId.Errorf("Failing Koji job failed: %v", err)
}
@ -305,13 +313,19 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
}
}
// Make sure StartTime cannot overflow the int64 conversion
if args.StartTime > math.MaxInt64 {
return fmt.Errorf("StartTime integer overflow: %d", args.StartTime)
}
/* #nosec G115 */
startTime := int64(args.StartTime)
build := koji.Build{
BuildID: initArgs.BuildID,
TaskID: args.TaskID,
Name: args.Name,
Version: args.Version,
Release: args.Release,
StartTime: int64(args.StartTime),
StartTime: startTime,
EndTime: time.Now().Unix(),
Extra: koji.BuildExtra{
TypeInfo: koji.TypeInfoBuild{

View file

@ -39,7 +39,7 @@ type connectionConfig struct {
type kojiServer struct {
creds koji.GSSAPICredentials
relaxTimeoutFactor uint
relaxTimeoutFactor time.Duration
}
// Represents the implementation of a job type as defined by the worker API.