summaryrefslogtreecommitdiffstats
path: root/services/net
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2015-03-31 16:26:57 +0900
committerLorenzo Colitti <lorenzo@google.com>2015-04-01 13:55:34 +0900
commitc2abb2bf5efa901d747fe1dc020ba3361c60b45e (patch)
tree538d006a91006357e2a734c556399c1b4a7eb39f /services/net
parent3dda1fa418cb8eb426ca29c579baf8e4a84b72ba (diff)
downloadframeworks_base-c2abb2bf5efa901d747fe1dc020ba3361c60b45e.zip
frameworks_base-c2abb2bf5efa901d747fe1dc020ba3361c60b45e.tar.gz
frameworks_base-c2abb2bf5efa901d747fe1dc020ba3361c60b45e.tar.bz2
Deal with null characters in string options.
This currently truncates all strings at the first NULL character, except for vendorInfo, which is an opaque string. Bug: 19985674 Change-Id: Ie53b2c55eb8a5204d7b2c7e2d8587743d923647a
Diffstat (limited to 'services/net')
-rw-r--r--services/net/java/android/net/dhcp/DhcpPacket.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/services/net/java/android/net/dhcp/DhcpPacket.java b/services/net/java/android/net/dhcp/DhcpPacket.java
index a232a6e..d41629d 100644
--- a/services/net/java/android/net/dhcp/DhcpPacket.java
+++ b/services/net/java/android/net/dhcp/DhcpPacket.java
@@ -611,10 +611,22 @@ abstract class DhcpPacket {
/**
* Reads a string of specified length from the buffer.
*/
- private static String readAsciiString(ByteBuffer buf, int byteCount) {
+ private static String readAsciiString(ByteBuffer buf, int byteCount, boolean nullOk) {
byte[] bytes = new byte[byteCount];
buf.get(bytes);
- return new String(bytes, 0, bytes.length, StandardCharsets.US_ASCII);
+ int length = bytes.length;
+ if (!nullOk) {
+ // Stop at the first null byte. This is because some DHCP options (e.g., the domain
+ // name) are passed to netd via FrameworkListener, which refuses arguments containing
+ // null bytes. We don't do this by default because vendorInfo is an opaque string which
+ // could in theory contain null bytes.
+ for (length = 0; length < bytes.length; length++) {
+ if (bytes[length] == 0) {
+ break;
+ }
+ }
+ }
+ return new String(bytes, 0, length, StandardCharsets.US_ASCII);
}
/**
@@ -797,7 +809,7 @@ abstract class DhcpPacket {
break;
case DHCP_HOST_NAME:
expectedLen = optionLen;
- hostName = readAsciiString(packet, optionLen);
+ hostName = readAsciiString(packet, optionLen, false);
break;
case DHCP_MTU:
expectedLen = 2;
@@ -805,7 +817,7 @@ abstract class DhcpPacket {
break;
case DHCP_DOMAIN_NAME:
expectedLen = optionLen;
- domainName = readAsciiString(packet, optionLen);
+ domainName = readAsciiString(packet, optionLen, false);
break;
case DHCP_BROADCAST_ADDRESS:
bcAddr = readIpAddress(packet);
@@ -834,7 +846,7 @@ abstract class DhcpPacket {
break;
case DHCP_MESSAGE:
expectedLen = optionLen;
- message = readAsciiString(packet, optionLen);
+ message = readAsciiString(packet, optionLen, false);
break;
case DHCP_MAX_MESSAGE_SIZE:
expectedLen = 2;
@@ -850,7 +862,7 @@ abstract class DhcpPacket {
break;
case DHCP_VENDOR_CLASS_ID:
expectedLen = optionLen;
- vendorId = readAsciiString(packet, optionLen);
+ vendorId = readAsciiString(packet, optionLen, true);
break;
case DHCP_CLIENT_IDENTIFIER: { // Client identifier
byte[] id = new byte[optionLen];