From 0e572cbcbf125ceb37d11638b5f05e646da1fc5d Mon Sep 17 00:00:00 2001 From: Michal Labedzki Date: Thu, 23 Apr 2015 08:58:21 +0200 Subject: androiddump: Fix warning about unneeded value Value from strtol is not needed in this case, but compiler complains about it, so check if value range is valid and other possible error that can be detected. Change-Id: I6a8eeb6d2cb62c155772201000eca4c16bc8a555 Reviewed-on: https://code.wireshark.org/review/8172 Reviewed-by: Alexis La Goutte Petri-Dish: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Michal Labedzki --- extcap/androiddump.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'extcap') diff --git a/extcap/androiddump.c b/extcap/androiddump.c index 22bc99fba6..46ccf9a87c 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -1140,10 +1140,18 @@ static int capture_android_bluetooth_hcidump(char *interface, char *fifo, if (hex == 0x01) { hex_data = new_hex_data; - strtol(hex_data, &new_hex_data, 16); + hex = strtol(hex_data, &new_hex_data, 16); + if (hex < 0 || hex >= 256 || hex_data == new_hex_data) { + printf("ERROR: data format error: %s\n", strerror(errno)); + return 101; + } hex_data = new_hex_data; - strtol(hex_data, &new_hex_data, 16); + hex = strtol(hex_data, &new_hex_data, 16); + if (hex < 0 || hex >= 256 || hex_data == new_hex_data) { + printf("ERROR: data format error: %s\n", strerror(errno)); + return 101; + } hex_data = new_hex_data; hex = strtol(hex_data, &new_hex_data, 16); @@ -1151,18 +1159,30 @@ static int capture_android_bluetooth_hcidump(char *interface, char *fifo, raw_length = hex + 4; } else if (hex == 0x04) { hex_data = new_hex_data; - strtol(hex_data, &new_hex_data, 16); + hex = strtol(hex_data, &new_hex_data, 16); + if (hex < 0 || hex >= 256 || hex_data == new_hex_data) { + printf("ERROR: data format error: %s\n", strerror(errno)); + return 101; + } hex_data = new_hex_data; hex = strtol(hex_data, &new_hex_data, 16); - raw_length = hex +3; + raw_length = hex + 3; } else if (hex == 0x02) { hex_data = new_hex_data; - strtol(hex_data, &new_hex_data, 16); + hex = strtol(hex_data, &new_hex_data, 16); + if (hex < 0 || hex >= 256 || hex_data == new_hex_data) { + printf("ERROR: data format error: %s\n", strerror(errno)); + return 101; + } hex_data = new_hex_data; - strtol(hex_data, &new_hex_data, 16); + hex = strtol(hex_data, &new_hex_data, 16); + if (hex < 0 || hex >= 256 || hex_data == new_hex_data) { + printf("ERROR: data format error: %s\n", strerror(errno)); + return 101; + } hex_data = new_hex_data; hex = strtol(hex_data, &new_hex_data, 16); -- cgit v1.2.3