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
This commit is contained in:
wgr523 2023-03-26 19:54:56 +08:00 committed by GitHub
parent 21c54fd1d6
commit 436faf34e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {