From 7c75083d38882bf952845ea512f68802a9fdbf8a Mon Sep 17 00:00:00 2001 From: Sungkyu Yoo Date: Sun, 19 Apr 2026 22:31:59 +0900 Subject: [PATCH 1/2] Potential fix for code scanning alert no. 19: Slice memory allocation with excessive size value Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- internal/dashboard/logger.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/dashboard/logger.go b/internal/dashboard/logger.go index 34fe9d4..52db32a 100644 --- a/internal/dashboard/logger.go +++ b/internal/dashboard/logger.go @@ -7,6 +7,11 @@ import ( "time" ) +const ( + defaultLogCollectorSize = 1000 + maxLogCollectorSize = 10000 +) + // RequestLog holds details about a single API request. type RequestLog struct { Method string `json:"method"` @@ -28,6 +33,13 @@ type LogCollector struct { // NewLogCollector creates a LogCollector that holds at most maxSize entries. func NewLogCollector(maxSize int) *LogCollector { + if maxSize <= 0 { + maxSize = defaultLogCollectorSize + } + if maxSize > maxLogCollectorSize { + maxSize = maxLogCollectorSize + } + return &LogCollector{ entries: make([]RequestLog, maxSize), maxSize: maxSize, @@ -52,6 +64,9 @@ func (c *LogCollector) Recent(n int) []RequestLog { c.mu.RLock() defer c.mu.RUnlock() + if n > c.maxSize { + n = c.maxSize + } if n > c.count { n = c.count } From 537f68136475dacbf2990c01e1c5e3c29725bbe0 Mon Sep 17 00:00:00 2001 From: Sung-Kyu Yoo Date: Tue, 21 Apr 2026 01:11:29 +0900 Subject: [PATCH 2/2] fix: simplify Recent() guard clauses in LogCollector Early-return on n <= 0 or empty buffer, and remove redundant n > c.maxSize check since c.count is already capped at maxSize. --- internal/dashboard/logger.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/dashboard/logger.go b/internal/dashboard/logger.go index 52db32a..3e01a32 100644 --- a/internal/dashboard/logger.go +++ b/internal/dashboard/logger.go @@ -64,15 +64,12 @@ func (c *LogCollector) Recent(n int) []RequestLog { c.mu.RLock() defer c.mu.RUnlock() - if n > c.maxSize { - n = c.maxSize + if n <= 0 || c.count == 0 { + return []RequestLog{} } if n > c.count { n = c.count } - if n <= 0 { - return []RequestLog{} - } result := make([]RequestLog, n) // cursor points to the slot that will be written next, so cursor-1 is the