diff options
author | Paul Stewart <pstew@google.com> | 2016-05-31 17:31:03 -0700 |
---|---|---|
committer | Jessica Wagantall <jwagantall@cyngn.com> | 2016-08-02 01:11:18 -0700 |
commit | d8d22e1b882a02ca3a75cae08966a2f4e2ea46f4 (patch) | |
tree | f900a8a3a6b651ea5fd591afc0f13c48b1a74493 | |
parent | cea450efef52ea0554e361272730078a2f7d7b81 (diff) | |
download | android_frameworks_opt_net_wifi-d8d22e1b882a02ca3a75cae08966a2f4e2ea46f4.tar.gz android_frameworks_opt_net_wifi-d8d22e1b882a02ca3a75cae08966a2f4e2ea46f4.tar.bz2 android_frameworks_opt_net_wifi-d8d22e1b882a02ca3a75cae08966a2f4e2ea46f4.zip |
Deal correctly with short strings
The parseMacAddress function anticipates only properly formed
MAC addresses (6 hexadecimal octets separated by ":"). This
change properly deals with situations where the string is
shorter than expected, making sure that the passed in char*
reference in parseHexByte never exceeds the end of the string.
BUG: 28164077
TEST: Added a main function:
int main(int argc, char **argv) {
unsigned char addr[6];
if (argc > 1) {
memset(addr, 0, sizeof(addr));
parseMacAddress(argv[1], addr);
printf("Result: %02x:%02x:%02x:%02x:%02x:%02x\n",
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
}
}
Tested with "", "a" "ab" "ab:c" "abxc".
Ticket: CYNGNOS-3177
Change-Id: I0db8d0037e48b62333d475296a45b22ab0efe386
(cherry picked from commit 1921acbf2c82dd0813b3734f2609fe6f971c9c2f)
-rw-r--r-- | service/jni/com_android_server_wifi_WifiNative.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp index d2cbe113f..a6d4f4ee9 100644 --- a/service/jni/com_android_server_wifi_WifiNative.cpp +++ b/service/jni/com_android_server_wifi_WifiNative.cpp @@ -763,15 +763,23 @@ static byte parseHexChar(char ch) { } static byte parseHexByte(const char * &str) { + if (str[0] == '\0') { + ALOGE("Passed an empty string"); + return 0; + } byte b = parseHexChar(str[0]); - if (str[1] == ':' || str[1] == '\0') { - str += 2; - return b; + if (str[1] == '\0' || str[1] == ':') { + str ++; } else { b = b << 4 | parseHexChar(str[1]); - str += 3; - return b; + str += 2; + } + + // Skip trailing delimiter if not at the end of the string. + if (str[0] != '\0') { + str++; } + return b; } static void parseMacAddress(const char *str, mac_addr addr) { |