better error handling of malformed symbol alias AST node for solc <0.6.0

pull/1547/head
alpharush 2 years ago
parent 2e1b50862f
commit df896e80f2
  1. 27
      slither/solc_parsing/slither_compilation_unit_solc.py
  2. 1
      tests/ast-parsing/complex_imports/import_aliases_issue_1319/import.sol
  3. 9
      tests/ast-parsing/complex_imports/import_aliases_issue_1319/test.sol
  4. 9
      tests/ast-parsing/complex_imports/import_aliases_issue_1319/test_fail.sol

@ -45,16 +45,22 @@ def _handle_import_aliases(
"""
for symbol_alias in symbol_aliases:
if (
"foreign" in symbol_alias
and "name" in symbol_alias["foreign"]
and "local" in symbol_alias
):
original_name = symbol_alias["foreign"]["name"]
local_name = symbol_alias["local"]
import_directive.renaming[local_name] = original_name
# Assuming that two imports cannot collide in renaming
scope.renaming[local_name] = original_name
if "foreign" in symbol_alias and "local" in symbol_alias:
if isinstance(symbol_alias["foreign"], dict) and "name" in symbol_alias["foreign"]:
original_name = symbol_alias["foreign"]["name"]
local_name = symbol_alias["local"]
import_directive.renaming[local_name] = original_name
# Assuming that two imports cannot collide in renaming
scope.renaming[local_name] = original_name
# This path should only be hit for the malformed AST of solc 0.5.12 where
# the foreign identifier cannot be found but is required to resolve the alias.
# see https://github.com/crytic/slither/issues/1319
if symbol_alias["local"]:
raise SlitherException(
"Cannot resolve local alias for import directive due to malformed AST. Please upgrade to solc 0.6.0 or higher."
)
class SlitherCompilationUnitSolc:
@ -389,7 +395,6 @@ Please rename it, this name is reserved for Slither's internals"""
)
self._contracts_by_id[contract.id] = contract
self._compilation_unit.contracts.append(contract)
# Update of the inheritance
for contract_parser in self._underlying_contract_to_parser.values():
# remove the first elem in linearizedBaseContracts as it is the contract itself

@ -0,0 +1,9 @@
pragma solidity 0.5.12;
import {A} from "./import.sol";
contract Z is A {
function test() public pure returns (uint) {
return 1;
}
}

@ -0,0 +1,9 @@
pragma solidity 0.5.12;
import {A as X, A as Y} from "./import.sol";
contract Z is X {
function test() public pure returns (uint) {
return 1;
}
}
Loading…
Cancel
Save