From de9d3bfb6519691c72d87259f1ab7ef4ea5846e6 Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Sun, 16 Feb 2025 21:10:56 +0800 Subject: [PATCH] Fixed netstat underflow bug - Fixed netstat sometime underflow to a large negative number bug --- src/mod/netstat/netstat.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/netstat/netstat.go b/src/mod/netstat/netstat.go index 078c1f6..67724c1 100644 --- a/src/mod/netstat/netstat.go +++ b/src/mod/netstat/netstat.go @@ -212,6 +212,10 @@ func (n *NetStatBuffers) GetNetworkInterfaceStats() (int64, int64, error) { totalTx += counter.BytesSent } - // Convert bytes to bits + // Convert bytes to bits with overflow check + const maxInt64 = int64(^uint64(0) >> 1) + if totalRx*8 > uint64(maxInt64) || totalTx*8 > uint64(maxInt64) { + return 0, 0, errors.New("overflow detected when converting uint64 to int64") + } return int64(totalRx * 8), int64(totalTx * 8), nil }