Merge pull request #3043 from chengzhichao-xydt/codex/atoi-gateway-json

fix: check strconv.Atoi and json.Unmarshal errors
This commit is contained in:
Mauro 2026-06-10 23:58:23 +02:00 committed by GitHub
commit bc6179917c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -88,7 +88,12 @@ func ResolveGatewayLogLevel(path string) string {
data, err := os.ReadFile(path) data, err := os.ReadFile(path)
if err == nil { if err == nil {
_ = json.Unmarshal(data, &cfg) if err := json.Unmarshal(data, &cfg); err != nil {
logger.WarnCF("config", "failed to parse gateway config, using defaults", map[string]any{
"path": path,
"error": err.Error(),
})
}
} }
if envLevel := os.Getenv("PICOCLAW_LOG_LEVEL"); envLevel != "" { if envLevel := os.Getenv("PICOCLAW_LOG_LEVEL"); envLevel != "" {

View file

@ -22,7 +22,10 @@ func ParseLastDuration(s string) (time.Duration, error) {
return 0, fmt.Errorf("invalid duration format: %q (use format like 6h, 7d, 2w, 1m)", s) return 0, fmt.Errorf("invalid duration format: %q (use format like 6h, 7d, 2w, 1m)", s)
} }
value, _ := strconv.Atoi(matches[1]) value, err := strconv.Atoi(matches[1])
if err != nil {
return 0, fmt.Errorf("invalid duration value: %q", matches[1])
}
unit := matches[2] unit := matches[2]
switch unit { switch unit {