Potential fix for code scanning alert no. 6: Slice memory allocation with excessive size value

This commit is contained in:
sam authored and GitHub committed 2026-09-03 15:13:35 +10:00
1 parent bf7115fcb5
commit 378c0e82d6
2 files changed
+32 -2

No files matched your search

+16 -1
View File
@@ -32,7 +32,22 @@ func (s *Server) handleLogs(w http.ResponseWriter, r *http.Request) {
}
q := r.URL.Query()
limit, _ := strconv.Atoi(q.Get("limit"))
limit := logging.DefaultTailLines
if raw := strings.TrimSpace(q.Get("limit")); raw != "" {
parsed, err := strconv.Atoi(raw)
if err != nil {
http.Error(w, "bad limit", http.StatusBadRequest)
return
}
switch {
case parsed <= 0:
limit = logging.DefaultTailLines
case parsed > logging.MaxTailLines:
limit = logging.MaxTailLines
default:
limit = parsed
}
}
result, err := logging.Tail(path, logging.Query{
Levels: splitCSV(q.Get("level")),
Component: strings.TrimSpace(q.Get("component")),
+16 -1
View File
@@ -56,7 +56,22 @@ func (s *Server) handleTaskLogs(w http.ResponseWriter, r *http.Request) {
return
}
limit, _ := strconv.Atoi(q.Get("limit"))
limit := logging.DefaultTailLines
if raw := strings.TrimSpace(q.Get("limit")); raw != "" {
parsed, err := strconv.Atoi(raw)
if err != nil {
http.Error(w, "bad limit", http.StatusBadRequest)
return
}
switch {
case parsed <= 0:
limit = logging.DefaultTailLines
case parsed > logging.MaxTailLines:
limit = logging.MaxTailLines
default:
limit = parsed
}
}
result, err := logging.Tail(path, logging.Query{
Levels: splitCSV(q.Get("level")),
Component: strings.TrimSpace(q.Get("component")),