Merge pull request #949 from ConsenSys/bugfix/lineno

Handle -1 case in solidity file mapping
pull/969/head
Nikhil Parasaram 6 years ago committed by GitHub
commit 6518fd6ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      mythril/analysis/report.py
  2. 15
      mythril/solidity/soliditycontract.py
  3. 5
      mythril/support/truffle.py

@ -107,6 +107,17 @@ class Issue:
return issue
def _set_internal_compiler_error(self):
"""
Adds the false positive to description and changes severity to low
"""
self.severity = "Low"
self.description_tail += (
" This issue is reported for internal compiler generated code."
)
self.description = "%s\n%s" % (self.description_head, self.description_tail)
self.code = ""
def add_code_info(self, contract):
"""
@ -119,6 +130,8 @@ class Issue:
self.filename = codeinfo.filename
self.code = codeinfo.code
self.lineno = codeinfo.lineno
if self.lineno is None:
self._set_internal_compiler_error()
self.source_mapping = codeinfo.solc_mapping
else:
self.source_mapping = self.address

@ -161,11 +161,14 @@ class SolidityContract(EVMContract):
if len(mapping) > 2 and len(mapping[2]) > 0:
idx = int(mapping[2])
lineno = (
self.solidity_files[idx]
.data.encode("utf-8")[0:offset]
.count("\n".encode("utf-8"))
+ 1
)
if idx == -1:
lineno = None
else:
lineno = (
self.solidity_files[idx]
.data.encode("utf-8")[0:offset]
.count("\n".encode("utf-8"))
+ 1
)
prev_item = item
mappings.append(SourceMapping(idx, offset, length, lineno, item))

@ -194,7 +194,10 @@ def get_mappings(source, deployed_source_map):
if len(mapping) > 2 and len(mapping[2]) > 0:
idx = int(mapping[2])
lineno = source.encode("utf-8")[0:offset].count("\n".encode("utf-8")) + 1
if idx == -1:
lineno = None
else:
lineno = source.encode("utf-8")[0:offset].count("\n".encode("utf-8")) + 1
prev_item = item
mappings.append(SourceMapping(idx, offset, length, lineno, item))

Loading…
Cancel
Save