GithubHelp home page GithubHelp logo

iprange's People

Contributors

xiam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

iprange's Issues

Invalid masks cause panic

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
}

Solution

I am not very familiar with the codebase so these might be way off.

  • Quick: Check mask' and minvalues in [y.go#L502](https://github.com/malfunkt/iprange/blob/master/y.go#L502) before passing it toUint32`
  • Not quick but IMO better solution: Check input for validity before passing it down. For example check if mask value is valid (16-30 if I am not mistaken).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.