Loading services/net/java/android/net/dhcp/DhcpPacket.java +5 −1 Original line number Diff line number Diff line Loading @@ -804,7 +804,11 @@ abstract class DhcpPacket { // server-to-server packets, e.g. for relays. if (!isPacketToOrFromClient(udpSrcPort, udpDstPort) && !isPacketServerToServer(udpSrcPort, udpDstPort)) { return null; // This should almost never happen because we use SO_ATTACH_FILTER on the packet // socket to drop packets that don't have the right source ports. However, it's // possible that a packet arrives between when the socket is bound and when the // filter is set. http://b/26696823 . throw new ParseException("Unexpected UDP ports %d->%d", udpSrcPort, udpDstPort); } } Loading services/tests/servicestests/src/android/net/dhcp/DhcpPacketTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -551,6 +551,39 @@ public class DhcpPacketTest extends TestCase { "wvm.edu", "10.1.105.252", null, 86400, false, dhcpResults); } @SmallTest public void testUdpInvalidDstPort() throws Exception { final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode(( // Ethernet header. "9cd917000000001c2e0000000800" + // IP header. "45a00148000040003d115087d18194fb0a0f7af2" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation). // NOTE: The destination port is a non-DHCP port. "0043aaaa01341268" + // BOOTP header. "02010600d628ba8200000000000000000a0f7af2000000000a0fc818" + // MAC address. "9cd91700000000000000000000000000" + // Server name. "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File. "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options. "6382536335010236040a0169fc3304000151800104ffff000003040a0fc817060cd1818003d1819403" + "d18180060f0777766d2e6564751c040a0fffffff000000" ).toCharArray(), false)); try { DhcpPacket.decodeFullPacket(packet, ENCAP_L2); fail("Packet with invalid dst port did not throw ParseException"); } catch (ParseException expected) {} } @SmallTest public void testMultipleRouters() throws Exception { final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode(( Loading Loading
services/net/java/android/net/dhcp/DhcpPacket.java +5 −1 Original line number Diff line number Diff line Loading @@ -804,7 +804,11 @@ abstract class DhcpPacket { // server-to-server packets, e.g. for relays. if (!isPacketToOrFromClient(udpSrcPort, udpDstPort) && !isPacketServerToServer(udpSrcPort, udpDstPort)) { return null; // This should almost never happen because we use SO_ATTACH_FILTER on the packet // socket to drop packets that don't have the right source ports. However, it's // possible that a packet arrives between when the socket is bound and when the // filter is set. http://b/26696823 . throw new ParseException("Unexpected UDP ports %d->%d", udpSrcPort, udpDstPort); } } Loading
services/tests/servicestests/src/android/net/dhcp/DhcpPacketTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -551,6 +551,39 @@ public class DhcpPacketTest extends TestCase { "wvm.edu", "10.1.105.252", null, 86400, false, dhcpResults); } @SmallTest public void testUdpInvalidDstPort() throws Exception { final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode(( // Ethernet header. "9cd917000000001c2e0000000800" + // IP header. "45a00148000040003d115087d18194fb0a0f7af2" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation). // NOTE: The destination port is a non-DHCP port. "0043aaaa01341268" + // BOOTP header. "02010600d628ba8200000000000000000a0f7af2000000000a0fc818" + // MAC address. "9cd91700000000000000000000000000" + // Server name. "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File. "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options. "6382536335010236040a0169fc3304000151800104ffff000003040a0fc817060cd1818003d1819403" + "d18180060f0777766d2e6564751c040a0fffffff000000" ).toCharArray(), false)); try { DhcpPacket.decodeFullPacket(packet, ENCAP_L2); fail("Packet with invalid dst port did not throw ParseException"); } catch (ParseException expected) {} } @SmallTest public void testMultipleRouters() throws Exception { final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode(( Loading