-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 [Bug]: utils.IsIPv4 and net.ParseIP have inconsistent results #2735
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Lines 9 to 39 in 2374cad
func IsIPv4(s string) bool {
for i := 0; i < net.IPv4len; i++ {
if len(s) == 0 {
return false
}
if i > 0 {
if s[0] != '.' {
return false
}
s = s[1:]
}
n, ci := 0, 0
for ci = 0; ci < len(s) && '0' <= s[ci] && s[ci] <= '9'; ci++ {
n = n*10 + int(s[ci]-'0')
if n > 0xFF { // change
return false
}
}
if ci == 0 || (ci > 1 && s[0] == '0') {
return false
}
s = s[ci:]
}
return len(s) == 0
} could you test this ? |
0xFF is 255 |
it was passed. utils.IsIPv4("123.117.56.255") // return true |
ok, can you create a pull request that contains the fix and other unittest cases or should I do that? |
Bug Description
if config EnableIPValidation set true, The correct IP is filtered.
cause:
utils.IsIPv4 and net.ParseIP have inconsistent results
utils.IsIPv4("123.117.56.255") // return fasle
ip := net.ParseIP("123.117.56.255")
ip.To4() != nil // return true
How to Reproduce
IP address ending with .255, utils.IsIPv4 always returns false.
Expected Behavior
utils.IsIPv4("123.117.56.255") return true
Fiber Version
v2.49.2
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: