fix(agent): add safety check for read returning negative bytes (#1799)

This commit is contained in:
henrygd
2026-04-07 18:41:22 -04:00
parent c3dffff5e4
commit ea80f3c5a2
2 changed files with 5 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"io"
"math"
"os"
@@ -68,6 +69,9 @@ func ReadStringFileLimited(path string, maxSize int) (string, error) {
if err != nil && err != io.EOF {
return "", err
}
if n < 0 {
return "", fmt.Errorf("%s returned negative bytes: %d", path, n)
}
return strings.TrimSpace(string(buf[:n])), nil
}