From bd9ce6638ec9daa5c658e6b29841ea32f7d3287e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 12 Oct 2024 10:54:08 +0200 Subject: [PATCH] get rid of remaining nolint:gosec --- internal/media/util.go | 2 +- internal/middleware/logger.go | 2 +- internal/middleware/requestid.go | 2 +- internal/middleware/throttling.go | 6 +++++- internal/processing/admin/emoji.go | 7 +++---- internal/typeutils/internaltofrontend.go | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/media/util.go b/internal/media/util.go index f05573bd9..f6bf06260 100644 --- a/internal/media/util.go +++ b/internal/media/util.go @@ -145,7 +145,7 @@ func drainToTmp(rc io.ReadCloser) (string, error) { // Check to see if limit was reached, // (produces more useful error messages). if lr != nil && lr.N <= 0 { - err := fmt.Errorf("reached read limit %s", bytesize.Size(limit)) //nolint:gosec + err := fmt.Errorf("reached read limit %s", bytesize.Size(limit)) // #nosec G115 -- Just logging return path, gtserror.SetLimitReached(err) } diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go index b21b4d072..da5be9dfa 100644 --- a/internal/middleware/logger.go +++ b/internal/middleware/logger.go @@ -123,7 +123,7 @@ func Logger(logClientIP bool) gin.HandlerFunc { } // Generate a nicer looking bytecount - size := bytesize.Size(c.Writer.Size()) //nolint:gosec + size := bytesize.Size(c.Writer.Size()) // #nosec G115 -- Just logging // Finally, write log entry with status text + body size. l.Logf(lvl, "%s: wrote %s", statusText, size) diff --git a/internal/middleware/requestid.go b/internal/middleware/requestid.go index 3ed3c1a98..7d98787a7 100644 --- a/internal/middleware/requestid.go +++ b/internal/middleware/requestid.go @@ -48,7 +48,7 @@ func NewRequestID() string { b := make([]byte, 12) // Get current time in milliseconds. - ms := uint64(time.Now().UnixMilli()) //nolint:gosec + ms := uint64(time.Now().UnixMilli()) // #nosec G115 -- Pre-1970 clock? // Store binary time data in byte buffer. binary.LittleEndian.PutUint64(b[0:8], ms) diff --git a/internal/middleware/throttling.go b/internal/middleware/throttling.go index fb5a0f1ef..739189b79 100644 --- a/internal/middleware/throttling.go +++ b/internal/middleware/throttling.go @@ -82,12 +82,16 @@ func Throttle(cpuMultiplier int, retryAfter time.Duration) gin.HandlerFunc { return func(c *gin.Context) {} } + if retryAfter < 0 { + retryAfter = 0 + } + var ( limit = runtime.GOMAXPROCS(0) * cpuMultiplier queueLimit = limit * cpuMultiplier tokens = make(chan token, limit) requestCount = atomic.Int64{} - retryAfterStr = strconv.FormatUint(uint64(retryAfter/time.Second), 10) //nolint:gosec + retryAfterStr = strconv.FormatUint(uint64(retryAfter/time.Second), 10) // #nosec G115 -- Checked right above ) // prefill token channel diff --git a/internal/processing/admin/emoji.go b/internal/processing/admin/emoji.go index b5ed66eed..03e8b486b 100644 --- a/internal/processing/admin/emoji.go +++ b/internal/processing/admin/emoji.go @@ -25,7 +25,6 @@ "mime/multipart" "strings" - "codeberg.org/gruf/go-bytesize" "codeberg.org/gruf/go-iotools" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -300,11 +299,11 @@ func (p *Processor) emojiUpdateCopy( } // Get maximum supported local emoji size. - maxsz := config.GetMediaEmojiLocalMaxSize() + maxsz := int(config.GetMediaEmojiLocalMaxSize()) // #nosec G115 -- Already validated // Ensure target emoji image within size bounds. - if bytesize.Size(target.ImageFileSize) > maxsz { //nolint:gosec - text := fmt.Sprintf("emoji exceeds configured max size: %s", maxsz) + if target.ImageFileSize > maxsz { + text := fmt.Sprintf("emoji exceeds configured max size: %d", maxsz) return nil, gtserror.NewErrorBadRequest(errors.New(text), text) } diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 9e073aecf..1e20455c3 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1531,7 +1531,7 @@ func (c *Converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Ins Registrations: config.GetAccountsRegistrationOpen(), ApprovalRequired: true, // approval always required InvitesEnabled: false, // todo: not supported yet - MaxTootChars: uint(config.GetStatusesMaxChars()), //nolint:gosec + MaxTootChars: uint(config.GetStatusesMaxChars()), // #nosec G115 -- Already validated. Rules: c.InstanceRulesToAPIRules(i.Rules), Terms: i.Terms, TermsRaw: i.TermsText,