Potential fix for code scanning alert no. 6: Slice memory allocation with excessive size value
This commit is contained in:
1 parent
bf7115fcb5
commit
378c0e82d6
2 files changed
+32
-2
No files matched your search
@@ -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")),
|
||||
|
||||
@@ -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")),
|
||||
|
||||
Reference in new issue
Block a user