aboutsummaryrefslogtreecommitdiff
path: root/bytesconv.go
diff options
context:
space:
mode:
authorGravatar Oleksandr Redko <oleksandr.red+github@gmail.com> 2024-03-29 15:11:50 +0200
committerGravatar GitHub <noreply@github.com> 2024-03-29 14:11:50 +0100
commite28be0c9931e98f797c662a805058e3d791fe3f5 (patch)
tree3bf1bde0d45266f886879b68bd324c1723618481 /bytesconv.go
parenttest: remove redundant error check (#1741) (diff)
downloadfasthttp-e28be0c9931e98f797c662a805058e3d791fe3f5.tar.gz
fasthttp-e28be0c9931e98f797c662a805058e3d791fe3f5.tar.bz2
fasthttp-e28be0c9931e98f797c662a805058e3d791fe3f5.zip
fix: panic in ParseIPv4 when len(dst) > 4 (#1742)
Diffstat (limited to 'bytesconv.go')
-rw-r--r--bytesconv.go8
1 files changed, 2 insertions, 6 deletions
diff --git a/bytesconv.go b/bytesconv.go
index 4e36d1d..dddf24f 100644
--- a/bytesconv.go
+++ b/bytesconv.go
@@ -73,15 +73,11 @@ func ParseIPv4(dst net.IP, ipStr []byte) (net.IP, error) {
if len(ipStr) == 0 {
return dst, errEmptyIPStr
}
- if len(dst) < net.IPv4len {
+ if len(dst) < net.IPv4len || len(dst) > net.IPv4len {
dst = make([]byte, net.IPv4len)
}
copy(dst, net.IPv4zero)
- dst = dst.To4()
- if dst == nil {
- // developer sanity-check
- panic("BUG: dst must not be nil")
- }
+ dst = dst.To4() // dst is always non-nil here
b := ipStr
for i := 0; i < 3; i++ {