malfunkt / iprange Goto Github PK
View Code? Open in Web Editor NEWIPv4 address parser for the nmap format
License: MIT License
IPv4 address parser for the nmap format
License: MIT License
This minimal example for 10.0.0.0/40
package main
import (
"github.com/malfunkt/iprange"
)
func main() {
_, _ = iprange.ParseList("10.0.0.0/40")
}
results in a panic:
$ go run test1.go
panic: runtime error: index out of range
goroutine 1 [running]:
encoding/binary.binary.bigEndian.Uint32(...)
Go/src/encoding/binary/binary.go:111
github.com/malfunkt/iprange.(*ipParserImpl).Parse(0xc04209e000, 0x500ba0, 0xc04209c050, 0x0)
yaccpar:355 +0x2007
github.com/malfunkt/iprange.ipParse(0x500ba0, 0xc04209c050, 0xb)
yaccpar:153 +0x5f
github.com/malfunkt/iprange.ParseList(0x4ec90f, 0xb, 0x0, 0x0, 0x4b2533, 0xc042085f78, 0xc042054058)
ip.y:93 +0xbe
main.main()
test1.go:8 +0x3d
exit status 2
With an invalid mask, the mask
variable coming from net.CIDRMask
at https://github.com/malfunkt/iprange/blob/master/y.go#L502 is nil
:
case 5:
ipDollar = ipS[ippt-3 : ippt+1]
//line ip.y:54
{
mask := net.CIDRMask(int(ipDollar[3].num), 32) // mask == nil if original mask is invalid
min := ipDollar[1].addrRange.Min.Mask(mask) // min == nil in this case too
maxInt := binary.BigEndian.Uint32([]byte(min)) +
0xffffffff -
binary.BigEndian.Uint32([]byte(mask)) // nil passed to Uint32 causes a panic
maxBytes := make([]byte, 4)
Passing a nil
or short byte[]
to `Uint32 results in a panic. The bounds check hint which causes the panic can be seen here:
func (bigEndian) Uint32(b []byte) uint32 {
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
}
I am not very familiar with the codebase so these might be way off.
mask' and
minvalues in [y.go#L502](https://github.com/malfunkt/iprange/blob/master/y.go#L502) before passing it to
Uint32`A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.