Fix sscanf VS Code Analysis warnings.

Some needed to check return value, others were converted to use strtoul.

Change-Id: I55aae216f95362b67e006f6e682abbd5ae2c8dcc
Reviewed-on: https://code.wireshark.org/review/16502
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2016-07-16 13:06:28 -04:00
parent 379c3c6fde
commit 8cd167a06c
5 changed files with 95 additions and 88 deletions

View File

@ -788,9 +788,13 @@ get_full_ipv4_addr(char* ipv4_address_expanded, char *ipv4_address)
}
else
{
sscanf(addr_byte_string_tmp,"%u",&addr_byte);
if(addr_byte < 16) g_snprintf(addr_byte_string,4,"0%X",addr_byte);
else g_snprintf(addr_byte_string,4,"%X",addr_byte);
if (sscanf(addr_byte_string_tmp,"%u",&addr_byte) != 1)
return FALSE;
if(addr_byte < 16)
g_snprintf(addr_byte_string,4,"0%X",addr_byte);
else
g_snprintf(addr_byte_string,4,"%X",addr_byte);
for(i = 0; i < strlen(addr_byte_string); i++)
{
ipv4_address_expanded[cpt] = addr_byte_string[i];
@ -813,9 +817,13 @@ get_full_ipv4_addr(char* ipv4_address_expanded, char *ipv4_address)
}
else
{
sscanf(addr_byte_string_tmp,"%u",&addr_byte);
if(addr_byte < 16) g_snprintf(addr_byte_string,4,"0%X",addr_byte);
else g_snprintf(addr_byte_string,4,"%X",addr_byte);
if (sscanf(addr_byte_string_tmp,"%u",&addr_byte) != 1)
return FALSE;
if(addr_byte < 16)
g_snprintf(addr_byte_string,4,"0%X",addr_byte);
else
g_snprintf(addr_byte_string,4,"%X",addr_byte);
for(i = 0; i < strlen(addr_byte_string); i++)
{
ipv4_address_expanded[cpt] = addr_byte_string[i];
@ -908,8 +916,10 @@ filter_address_match(gchar *addr, gchar *filter, gint typ)
addr_string_tmp[0] = addr[i];
addr_string_tmp[1] = '\0';
sscanf(filter_string_tmp,"%x",&filter_tmp);
sscanf(addr_string_tmp,"%x",&addr_tmp);
if (sscanf(filter_string_tmp,"%x",&filter_tmp) != 1)
return FALSE;
if (sscanf(addr_string_tmp,"%x",&addr_tmp) != 1)
return FALSE;
for(i = 0; i < (filter_len % 4); i++)
{
if(((filter_tmp >> (4 -i -1)) & 1) != ((addr_tmp >> (4 -i -1)) & 1))

View File

@ -585,30 +585,26 @@ attr_list(proto_tree *tree, packet_info* pinfo, int hf, tvbuff_t *tvb, int offse
}
if (svc == 50) {
byte_value = unicode_to_bytes(tvb, foffset, 16, TRUE); /* IP Address */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
proto_tree_add_ipv4(srvloc_tree, hf_srvloc_add_ref_ip, tvb, foffset+2, 16, prot);
byte_value = unicode_to_bytes(tvb, foffset+18, 8, FALSE); /* Port */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
ti = proto_tree_add_uint(srvloc_tree, hf_srvloc_port, tvb, foffset+18, 4, prot);
proto_item_set_len(ti, 8);
}
else
{
byte_value = unicode_to_bytes(tvb, foffset+2, 16, FALSE); /* IPX Network Address */
prot = 0;
prot = (guint32)strtoul(byte_value, NULL, 16);
sscanf(byte_value,"%x",&prot);
ti = proto_tree_add_uint(srvloc_tree, hf_srvloc_network, tvb, foffset+2, 4, prot);
proto_item_set_len(ti, 16);
byte_value = unicode_to_bytes(tvb, foffset+18, 24, FALSE); /* IPX Node Address */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
ti = proto_tree_add_uint(srvloc_tree, hf_srvloc_node, tvb, foffset+18, 4, prot);
proto_item_set_len(ti, 24);
byte_value = unicode_to_bytes(tvb, foffset+42, 8, FALSE); /* Socket */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
ti = proto_tree_add_uint(srvloc_tree, hf_srvloc_socket, tvb, foffset+42, 4, prot);
proto_item_set_len(ti, 8);
}
@ -661,29 +657,24 @@ attr_list(proto_tree *tree, packet_info* pinfo, int hf, tvbuff_t *tvb, int offse
}
if (svc == 50) {
byte_value = unicode_to_bytes(tvb, foffset, 8, TRUE); /* IP Address */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
proto_tree_add_ipv4(srvloc_tree, hf_srvloc_add_ref_ip, tvb, foffset+1, 8, prot);
byte_value = unicode_to_bytes(tvb, foffset+9, 4, FALSE); /* Port */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
proto_tree_add_uint(srvloc_tree, hf_srvloc_port, tvb, foffset+9, 4, prot);
}
else
{
byte_value = unicode_to_bytes(tvb, foffset+1, 8, FALSE); /* IPX Network Address */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
ti = proto_tree_add_uint(srvloc_tree, hf_srvloc_network, tvb, foffset+1, 4, prot);
proto_item_set_len(ti, 8);
byte_value = unicode_to_bytes(tvb, foffset+9, 12, FALSE); /* IPX Node Address */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
ti = proto_tree_add_uint(srvloc_tree, hf_srvloc_node, tvb, foffset+9, 4, prot);
proto_item_set_len(ti, 12);
byte_value = unicode_to_bytes(tvb, foffset+21, 4, FALSE); /* Socket */
prot = 0;
sscanf(byte_value,"%x",&prot);
prot = (guint32)strtoul(byte_value, NULL, 16);
proto_tree_add_uint(srvloc_tree, hf_srvloc_socket, tvb, foffset+21, 4, prot);
}
i++;

View File

@ -8215,11 +8215,12 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
if((strstr(puffer, vendorIdStr)) != NULL) {
memset (convertStr, 0, sizeof(*convertStr));
pch = strstr(puffer, vendorIdStr);
sscanf(pch, "VendorID=\"%[^\"]", convertStr);
read_vendor_id = (guint32) strtoul (convertStr, NULL, 0);
if (sscanf(pch, "VendorID=\"%[^\"]", convertStr) == 1) {
read_vendor_id = (guint32) strtoul (convertStr, NULL, 0);
if(read_vendor_id == searchVendorID) {
vendorMatch = TRUE; /* found correct VendorID */
if(read_vendor_id == searchVendorID) {
vendorMatch = TRUE; /* found correct VendorID */
}
}
}
@ -8227,11 +8228,12 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
if((strstr(puffer, deviceIdStr)) != NULL) {
memset(convertStr, 0, sizeof(*convertStr));
pch = strstr(puffer, deviceIdStr);
sscanf(pch, "DeviceID=\"%[^\"]", convertStr);
read_device_id = (guint32)strtoul(convertStr, NULL, 0);
if (sscanf(pch, "DeviceID=\"%[^\"]", convertStr) == 1) {
read_device_id = (guint32)strtoul(convertStr, NULL, 0);
if(read_device_id == searchDeviceID) {
deviceMatch = TRUE; /* found correct DeviceID */
if(read_device_id == searchDeviceID) {
deviceMatch = TRUE; /* found correct DeviceID */
}
}
}
}
@ -8359,9 +8361,9 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
memset (convertStr, 0, sizeof(*convertStr));
pch = strstr(temp, fParameterIndexStr);
sscanf(pch, "Index=\"%[^\"]", convertStr);
io_data_object->fParameterIndexNr = (guint32)strtoul(convertStr, NULL, 0);
if (sscanf(pch, "Index=\"%[^\"]", convertStr) == 1) {
io_data_object->fParameterIndexNr = (guint32)strtoul(convertStr, NULL, 0);
}
break; /* found Indexnumber -> break search loop */
}
}
@ -8373,62 +8375,65 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
if((strstr(temp, moduleStr)) != NULL) { /* find the String "ModuleIdentNumber=" */
memset (convertStr, 0, sizeof(*convertStr));
pch = strstr(temp, moduleStr); /* search for "ModuleIdentNumber=\"" within GSD-file */
sscanf(pch, "ModuleIdentNumber=\"%[^\"]", convertStr); /* Change format of Value string-->numeric string */
read_module_id = (guint32)strtoul(convertStr, NULL, 0); /* Change numeric string --> unsigned long; read_module_id contains the Value of the ModuleIdentNumber */
if (sscanf(pch, "ModuleIdentNumber=\"%[^\"]", convertStr) == 1) { /* Change format of Value string-->numeric string */
read_module_id = (guint32)strtoul(convertStr, NULL, 0); /* Change numeric string --> unsigned long; read_module_id contains the Value of the ModuleIdentNumber */
/* If the found ModuleID matches with the wanted ModuleID, search for the Submodule and break */
if (read_module_id == io_data_object->moduleIdentNr) {
++io_data_object->amountInGSDML; /* Save the amount of same (!) Module- & SubmoduleIdentNr in one GSD-file */
/* If the found ModuleID matches with the wanted ModuleID, search for the Submodule and break */
if (read_module_id == io_data_object->moduleIdentNr) {
++io_data_object->amountInGSDML; /* Save the amount of same (!) Module- & SubmoduleIdentNr in one GSD-file */
while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
if((strstr(temp, moduleNameInfo)) != NULL) { /* find the String "<Name" for the TextID */
long filePosRecord;
while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
if((strstr(temp, moduleNameInfo)) != NULL) { /* find the String "<Name" for the TextID */
long filePosRecord;
sscanf(temp, "%*s TextId=\"%[^\"]", tmp_moduletext); /* saves the correct TextId for the next searchloop */
filePosRecord = ftell(fp); /* save the current position of the filepointer (Offset) */
/* ftell() may return -1 for error, don't move fp in this case */
if (filePosRecord >= 0) {
while (fgets(temp, MAX_LINE_LENGTH, fp) != NULL && io_data_object->amountInGSDML == 1) {
/* Find a String with the saved TextID and with a fitting value for it in the same line. This value is the name of the Module! */
if(((strstr(temp, tmp_moduletext)) != NULL) && ((strstr(temp, moduleValueInfo)) != NULL)) {
pch = strstr(temp, moduleValueInfo);
sscanf(pch, "Value=\"%[^\"]", io_data_object->moduleNameStr);
break; /* Found the name of the module */
}
}
fseek(fp, filePosRecord, SEEK_SET); /* set filepointer to the correct TextID */
}
}
/* Search for Submoduleidentnumber in GSD-file */
if((strstr(temp, subModuleStr)) != NULL) {
memset (convertStr, 0, sizeof(*convertStr));
pch = strstr(temp, subModuleStr);
sscanf(pch, "SubmoduleIdentNumber=\"%[^\"]", convertStr);
read_submodule_id = (guint32) strtoul (convertStr, NULL, 0); /* read_submodule_id contains the Value of the SubModuleIdentNumber */
/* Find "PROFIsafeSupported" flag of the module in GSD-file */
if(read_submodule_id == io_data_object->subModuleIdentNr) {
if((strstr(temp, profisafeStr)) != NULL) {
io_data_object->profisafeSupported = TRUE; /* flag is in the same line as SubmoduleIdentNr */
if (sscanf(temp, "%*s TextId=\"%[^\"]", tmp_moduletext) != 1) /* saves the correct TextId for the next searchloop */
break;
}
else { /* flag is not in the same line as Submoduleidentnumber -> search for it */
while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
if((strstr(temp, profisafeStr)) != NULL) {
io_data_object->profisafeSupported = TRUE;
break; /* Found the PROFIsafeSupported flag of the module */
}
else if((strstr(temp, ">")) != NULL) {
filePosRecord = ftell(fp); /* save the current position of the filepointer (Offset) */
/* ftell() may return -1 for error, don't move fp in this case */
if (filePosRecord >= 0) {
while (fgets(temp, MAX_LINE_LENGTH, fp) != NULL && io_data_object->amountInGSDML == 1) {
/* Find a String with the saved TextID and with a fitting value for it in the same line. This value is the name of the Module! */
if(((strstr(temp, tmp_moduletext)) != NULL) && ((strstr(temp, moduleValueInfo)) != NULL)) {
pch = strstr(temp, moduleValueInfo);
if (sscanf(pch, "Value=\"%[^\"]", io_data_object->moduleNameStr) == 1)
break; /* Found the name of the module */
}
}
fseek(fp, filePosRecord, SEEK_SET); /* set filepointer to the correct TextID */
}
}
/* Search for Submoduleidentnumber in GSD-file */
if((strstr(temp, subModuleStr)) != NULL) {
memset (convertStr, 0, sizeof(*convertStr));
pch = strstr(temp, subModuleStr);
if (sscanf(pch, "SubmoduleIdentNumber=\"%[^\"]", convertStr) == 1) {
read_submodule_id = (guint32) strtoul (convertStr, NULL, 0); /* read_submodule_id contains the Value of the SubModuleIdentNumber */
/* Find "PROFIsafeSupported" flag of the module in GSD-file */
if(read_submodule_id == io_data_object->subModuleIdentNr) {
if((strstr(temp, profisafeStr)) != NULL) {
io_data_object->profisafeSupported = TRUE; /* flag is in the same line as SubmoduleIdentNr */
break;
}
else { /* flag is not in the same line as Submoduleidentnumber -> search for it */
while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
if((strstr(temp, profisafeStr)) != NULL) {
io_data_object->profisafeSupported = TRUE;
break; /* Found the PROFIsafeSupported flag of the module */
}
else if((strstr(temp, ">")) != NULL) {
break;
}
}
}
}
break; /* Found the PROFIsafe Module */
}
}
break; /* Found the PROFIsafe Module */
}
}
}

View File

@ -345,7 +345,7 @@ follow_arg_filter(const char **opt_argp, follow_info_t *follow_info)
cli_follow_info_t* cli_follow_info = (cli_follow_info_t*)follow_info->gui_data;
gboolean is_ipv6;
if (sscanf(*opt_argp, ",%u%n", &cli_follow_info->stream_index, &len) == 1 &&
if (sscanf(*opt_argp, ",%d%n", &cli_follow_info->stream_index, &len) == 1 &&
((*opt_argp)[len] == 0 || (*opt_argp)[len] == ','))
{
*opt_argp += len;

View File

@ -1846,9 +1846,10 @@ airpcap_get_selected_channel_offset(GtkWidget *channel_offset_cb) {
{
if (airpcap_if_selected != NULL)
{
sscanf(off_str, "%d", &offset);
if (offset >= -1 && offset <= 1) {
retval = offset;
if (sscanf(off_str, "%d", &offset) == 1) {
if (offset >= -1 && offset <= 1) {
retval = offset;
}
}
}
}