Skip to content

Instantly share code, notes, and snippets.

@fcasal
Created October 31, 2022 14:04
Show Gist options
  • Save fcasal/a3b160322395b4399ba917a759e35151 to your computer and use it in GitHub Desktop.
Save fcasal/a3b160322395b4399ba917a759e35151 to your computer and use it in GitHub Desktop.
from typing import Dict, List
from amarna.rules.gatherer_rules.AllFunctionCallsGatherer import (
AllFunctionCallsGatherer,
FunctionCallType,
)
from amarna.rules.gatherer_rules.DeclaredFunctionsGatherer import (
DeclaredFunctionsGatherer,
FunctionType,
)
from amarna.Result import Result, create_result
class GetCallerAddressL1HandlerRule:
"""
Find calls to get_caller_address in a l1_handler.
"""
RULE_TEXT = "The function get_caller_address returns 0 when called in a l1_handler"
RULE_NAME = "get-caller-address-in-l1-handler"
def run_rule(self, gathered_data: Dict) -> List[Result]:
function_calls: List[FunctionCallType] = gathered_data[
AllFunctionCallsGatherer.GATHERER_NAME
]
declared_functions: List[FunctionType] = gathered_data[
DeclaredFunctionsGatherer.GATHERER_NAME
]
# first, get all functions that are a l1_handler
l1_handlers = [f for f in declared_functions if "l1_handler" in f.decorators]
# fill the results here
interesting_calls : List[FunctionCallType] = []
# then, get all calls to get_caller_address
# cross-check those: get all calls to get_caller_address that are in a l1_handler
# create results
results: List[Result] = []
for call in interesting_calls:
sarif = create_result(
call.file_name,
self.RULE_NAME,
self.RULE_TEXT,
call.position,
)
results.append(sarif)
return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment