From 436faf34e1c49fabe6aa3991b82ef1e827cffec9 Mon Sep 17 00:00:00 2001 From: wgr523 Date: Sun, 26 Mar 2023 19:54:56 +0800 Subject: [PATCH] Fix of discreason type problem (#242) Problem: https://github.com/advisories/GHSA-wjxw-gh3m-7pm5 Fix: add non-negative `if` condition. cannot use fix in geth (https://github.com/ethereum/go-ethereum/pull/24507) since modifying DiscReason to uint8 messes up the message encode --- p2p/peer_error.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/peer_error.go b/p2p/peer_error.go index 544d42315b..64530116e6 100644 --- a/p2p/peer_error.go +++ b/p2p/peer_error.go @@ -93,10 +93,10 @@ var discReasonToString = [...]string{ } func (d DiscReason) String() string { - if len(discReasonToString) < int(d) { + if len(discReasonToString) <= int(d) || int(d) < 0 { return fmt.Sprintf("unknown disconnect reason %d", d) } - return discReasonToString[d] + return discReasonToString[int(d)] } func (d DiscReason) Error() string {