Jonathan Hart

Protect against null pointers during deserializing.

Fixes ONOS-779.

Change-Id: I7e6a57457e287d28dd23946d677d3943443a435f
(cherry picked from commit eec29724)
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
16 package org.onosproject.openflow.controller; 16 package org.onosproject.openflow.controller;
17 17
18 18
19 -import java.nio.BufferUnderflowException;
20 -import java.util.Collections;
21 -import java.util.concurrent.atomic.AtomicBoolean;
22 -
23 import org.onlab.packet.Ethernet; 19 import org.onlab.packet.Ethernet;
24 import org.projectfloodlight.openflow.protocol.OFPacketIn; 20 import org.projectfloodlight.openflow.protocol.OFPacketIn;
25 import org.projectfloodlight.openflow.protocol.OFPacketOut; 21 import org.projectfloodlight.openflow.protocol.OFPacketOut;
...@@ -29,6 +25,10 @@ import org.projectfloodlight.openflow.protocol.match.MatchField; ...@@ -29,6 +25,10 @@ import org.projectfloodlight.openflow.protocol.match.MatchField;
29 import org.projectfloodlight.openflow.types.OFBufferId; 25 import org.projectfloodlight.openflow.types.OFBufferId;
30 import org.projectfloodlight.openflow.types.OFPort; 26 import org.projectfloodlight.openflow.types.OFPort;
31 27
28 +import java.nio.BufferUnderflowException;
29 +import java.util.Collections;
30 +import java.util.concurrent.atomic.AtomicBoolean;
31 +
32 public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext { 32 public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext {
33 33
34 private final AtomicBoolean free = new AtomicBoolean(true); 34 private final AtomicBoolean free = new AtomicBoolean(true);
...@@ -89,7 +89,7 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -89,7 +89,7 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
89 try { 89 try {
90 eth.deserialize(pktin.getData(), 0, pktin.getData().length); 90 eth.deserialize(pktin.getData(), 0, pktin.getData().length);
91 return eth; 91 return eth;
92 - } catch (BufferUnderflowException e) { 92 + } catch (BufferUnderflowException | NullPointerException e) {
93 return null; 93 return null;
94 } 94 }
95 } 95 }
......
...@@ -15,15 +15,16 @@ ...@@ -15,15 +15,16 @@
15 */ 15 */
16 package org.onosproject.provider.of.host.impl; 16 package org.onosproject.provider.of.host.impl;
17 17
18 -import static org.onosproject.net.DeviceId.deviceId;
19 -import static org.onosproject.net.PortNumber.portNumber;
20 -import static org.slf4j.LoggerFactory.getLogger;
21 -
22 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
25 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
26 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 +import org.onlab.packet.ARP;
24 +import org.onlab.packet.Ethernet;
25 +import org.onlab.packet.IPv4;
26 +import org.onlab.packet.IpAddress;
27 +import org.onlab.packet.VlanId;
27 import org.onosproject.net.ConnectPoint; 28 import org.onosproject.net.ConnectPoint;
28 import org.onosproject.net.Host; 29 import org.onosproject.net.Host;
29 import org.onosproject.net.HostId; 30 import org.onosproject.net.HostId;
...@@ -41,13 +42,12 @@ import org.onosproject.openflow.controller.Dpid; ...@@ -41,13 +42,12 @@ import org.onosproject.openflow.controller.Dpid;
41 import org.onosproject.openflow.controller.OpenFlowController; 42 import org.onosproject.openflow.controller.OpenFlowController;
42 import org.onosproject.openflow.controller.OpenFlowPacketContext; 43 import org.onosproject.openflow.controller.OpenFlowPacketContext;
43 import org.onosproject.openflow.controller.PacketListener; 44 import org.onosproject.openflow.controller.PacketListener;
44 -import org.onlab.packet.ARP;
45 -import org.onlab.packet.Ethernet;
46 -import org.onlab.packet.IPv4;
47 -import org.onlab.packet.IpAddress;
48 -import org.onlab.packet.VlanId;
49 import org.slf4j.Logger; 45 import org.slf4j.Logger;
50 46
47 +import static org.onosproject.net.DeviceId.deviceId;
48 +import static org.onosproject.net.PortNumber.portNumber;
49 +import static org.slf4j.LoggerFactory.getLogger;
50 +
51 /** 51 /**
52 * Provider which uses an OpenFlow controller to detect network 52 * Provider which uses an OpenFlow controller to detect network
53 * end-station hosts. 53 * end-station hosts.
...@@ -106,6 +106,10 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -106,6 +106,10 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
106 public void handlePacket(OpenFlowPacketContext pktCtx) { 106 public void handlePacket(OpenFlowPacketContext pktCtx) {
107 Ethernet eth = pktCtx.parsed(); 107 Ethernet eth = pktCtx.parsed();
108 108
109 + if (eth == null) {
110 + return;
111 + }
112 +
109 VlanId vlan = VlanId.vlanId(eth.getVlanID()); 113 VlanId vlan = VlanId.vlanId(eth.getVlanID());
110 ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())), 114 ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())),
111 portNumber(pktCtx.inPort())); 115 portNumber(pktCtx.inPort()));
......