|
|
@ -544,38 +544,42 @@ t']:(node.source_mapping['start']+node.source_mapping['length'])].split('=')[0]) |
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|
def create_patch_struct_uses(slither, patches, name, contract_name, in_file): |
|
|
|
def create_patch_struct_uses(slither, patches, name, contract_name, in_file): |
|
|
|
for contract in slither.contracts: |
|
|
|
for contract in slither.contracts: |
|
|
|
in_file_str = slither.source_code[in_file] |
|
|
|
if (contract.name == contract_name): |
|
|
|
# Check state variables of struct type |
|
|
|
target_contract = contract |
|
|
|
# To-do: Deep-check aggregate types (struct and mapping) |
|
|
|
for contract in slither.contracts: |
|
|
|
svs = contract.variables |
|
|
|
if (contract == target_contract or (contract in target_contract.derived_contracts)): |
|
|
|
for sv in svs: |
|
|
|
in_file_str = slither.source_code[in_file] |
|
|
|
if (str(sv.type) == contract_name + "." + name): |
|
|
|
# Check state variables of struct type |
|
|
|
old_str_of_interest = in_file_str[sv.source_mapping['start']:(sv.source_mapping['start']+sv.source_mapping['length'])] |
|
|
|
# To-do: Deep-check aggregate types (struct and mapping) |
|
|
|
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),old_str_of_interest, 1) |
|
|
|
svs = contract.variables |
|
|
|
patch = { |
|
|
|
for sv in svs: |
|
|
|
"detector" : "naming-convention (struct use)", |
|
|
|
if (str(sv.type) == contract_name + "." + name): |
|
|
|
"start" : sv.source_mapping['start'], |
|
|
|
old_str_of_interest = in_file_str[sv.source_mapping['start']:(sv.source_mapping['start']+sv.source_mapping['length'])] |
|
|
|
"end" : sv.source_mapping['start'] + sv.source_mapping['length'], |
|
|
|
|
|
|
|
"old_string" : old_str_of_interest, |
|
|
|
|
|
|
|
"new_string" : new_str_of_interest |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if not patch in patches[in_file]: |
|
|
|
|
|
|
|
patches[in_file].append(patch) |
|
|
|
|
|
|
|
# Check function+modifier locals+parameters+returns |
|
|
|
|
|
|
|
# To-do: Deep-check aggregate types (struct and mapping) |
|
|
|
|
|
|
|
fms = contract.functions + contract.modifiers |
|
|
|
|
|
|
|
for fm in fms: |
|
|
|
|
|
|
|
for v in fm.variables: |
|
|
|
|
|
|
|
if (str(v.type) == contract_name + "." + name): |
|
|
|
|
|
|
|
old_str_of_interest = in_file_str[v.source_mapping['start']:(v.source_mapping['start']+v.source_mapping['length'])] |
|
|
|
|
|
|
|
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),old_str_of_interest, 1) |
|
|
|
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),old_str_of_interest, 1) |
|
|
|
patch = { |
|
|
|
patch = { |
|
|
|
"detector" : "naming-convention (struct use)", |
|
|
|
"detector" : "naming-convention (struct use)", |
|
|
|
"start" : v.source_mapping['start'], |
|
|
|
"start" : sv.source_mapping['start'], |
|
|
|
"end" : v.source_mapping['start'] + v.source_mapping['length'], |
|
|
|
"end" : sv.source_mapping['start'] + sv.source_mapping['length'], |
|
|
|
"old_string" : old_str_of_interest, |
|
|
|
"old_string" : old_str_of_interest, |
|
|
|
"new_string" : new_str_of_interest |
|
|
|
"new_string" : new_str_of_interest |
|
|
|
} |
|
|
|
} |
|
|
|
if not patch in patches[in_file]: |
|
|
|
if not patch in patches[in_file]: |
|
|
|
patches[in_file].append(patch) |
|
|
|
patches[in_file].append(patch) |
|
|
|
# To-do: Check any other place/way where struct type is used (e.g. typecast) |
|
|
|
# Check function+modifier locals+parameters+returns |
|
|
|
|
|
|
|
# To-do: Deep-check aggregate types (struct and mapping) |
|
|
|
|
|
|
|
fms = contract.functions + contract.modifiers |
|
|
|
|
|
|
|
for fm in fms: |
|
|
|
|
|
|
|
for v in fm.variables: |
|
|
|
|
|
|
|
if (str(v.type) == contract_name + "." + name): |
|
|
|
|
|
|
|
old_str_of_interest = in_file_str[v.source_mapping['start']:(v.source_mapping['start']+v.source_mapping['length'])] |
|
|
|
|
|
|
|
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),old_str_of_interest, 1) |
|
|
|
|
|
|
|
patch = { |
|
|
|
|
|
|
|
"detector" : "naming-convention (struct use)", |
|
|
|
|
|
|
|
"start" : v.source_mapping['start'], |
|
|
|
|
|
|
|
"end" : v.source_mapping['start'] + v.source_mapping['length'], |
|
|
|
|
|
|
|
"old_string" : old_str_of_interest, |
|
|
|
|
|
|
|
"new_string" : new_str_of_interest |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if not patch in patches[in_file]: |
|
|
|
|
|
|
|
patches[in_file].append(patch) |
|
|
|
|
|
|
|
# To-do: Check any other place/way where struct type is used (e.g. typecast) |
|
|
|