Commit ec5a957f authored by Mikio Hara's avatar Mikio Hara

ipv4: don't crash with corrupted control messages

Change-Id: I474b5832672e699f1eba1487f7f793bed3c1ff83
Reviewed-on: https://go-review.googlesource.com/45113
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 59a0b19b
...@@ -83,14 +83,14 @@ func (cm *ControlMessage) Parse(b []byte) error { ...@@ -83,14 +83,14 @@ func (cm *ControlMessage) Parse(b []byte) error {
if lvl != iana.ProtocolIP { if lvl != iana.ProtocolIP {
continue continue
} }
switch typ { switch {
case ctlOpts[ctlTTL].name: case typ == ctlOpts[ctlTTL].name && l >= ctlOpts[ctlTTL].length:
ctlOpts[ctlTTL].parse(cm, m.Data(l)) ctlOpts[ctlTTL].parse(cm, m.Data(l))
case ctlOpts[ctlDst].name: case typ == ctlOpts[ctlDst].name && l >= ctlOpts[ctlDst].length:
ctlOpts[ctlDst].parse(cm, m.Data(l)) ctlOpts[ctlDst].parse(cm, m.Data(l))
case ctlOpts[ctlInterface].name: case typ == ctlOpts[ctlInterface].name && l >= ctlOpts[ctlInterface].length:
ctlOpts[ctlInterface].parse(cm, m.Data(l)) ctlOpts[ctlInterface].parse(cm, m.Data(l))
case ctlOpts[ctlPacketInfo].name: case typ == ctlOpts[ctlPacketInfo].name && l >= ctlOpts[ctlPacketInfo].length:
ctlOpts[ctlPacketInfo].parse(cm, m.Data(l)) ctlOpts[ctlPacketInfo].parse(cm, m.Data(l))
} }
} }
......
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ipv4_test
import (
"testing"
"golang.org/x/net/ipv4"
)
func TestControlMessageParseWithFuzz(t *testing.T) {
var cm ipv4.ControlMessage
for _, fuzz := range []string{
"\f\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00",
"\f\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00",
} {
cm.Parse([]byte(fuzz))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment