Skip to content

Commit 52f5f1f

Browse files
committed
fix(security): prevent integer overflow in disk metrics collection
- Add validation to ensure block size is positive before int64->uint64 conversion - Return error for invalid block sizes to prevent overflow issues - Resolves gosec G115 integer overflow warning in metrics_collector.go:425 Fixes integer overflow security vulnerability detected by gosec scan.
1 parent bb07b18 commit 52f5f1f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

internal/monitoring/metrics_collector.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,12 @@ func (mc *MetricsCollector) getDiskUsage(path string, metrics *SystemMetrics) er
421421
return fmt.Errorf("failed to get disk usage for %s: %w", path, err)
422422
}
423423

424-
// Calculate disk usage
424+
// Validate block size to prevent integer overflow
425+
if stat.Bsize <= 0 {
426+
return fmt.Errorf("invalid block size %d for path %s", stat.Bsize, path)
427+
}
428+
429+
// Safe conversion from int64 to uint64 after validation
425430
blockSize := uint64(stat.Bsize)
426431
metrics.DiskTotalBytes = stat.Blocks * blockSize
427432
metrics.DiskAvailableBytes = stat.Bavail * blockSize

0 commit comments

Comments
 (0)