<s> '''<STR_LIT>''' <EOL> import logging <EOL> import os <EOL> from . crash_base import Crash <EOL> from . crash_base import CrashError <EOL> from . . debuggers import registration <EOL> from . . fuzztools import hostinfo <EOL> try : <EOL> from . . analyzers import pin_calltrace <EOL> from . . analyzers import AnalyzerEmptyOutputError <EOL> from . . debuggers . output_parsers . calltracefile import Calltracefile <EOL> except ImportError : <EOL> pass <EOL> logger = logging . getLogger ( __name__ ) <EOL> logger . setLevel ( logging . DEBUG ) <EOL> debugger = None <EOL> host_info = hostinfo . HostInfo ( ) <EOL> class BffCrash ( Crash ) : <EOL> '''<STR_LIT>''' <EOL> tmpdir_pfx = '<STR_LIT>' <EOL> def __init__ ( self , cfg , seedfile , fuzzedfile , program , <EOL> debugger_timeout , killprocname , backtrace_lines , <EOL> crashers_dir , seednum = None , range = None , keep_faddr = False ) : <EOL> '''<STR_LIT>''' <EOL> super ( self . __class__ , self ) . __init__ ( seedfile , fuzzedfile , debugger_timeout ) <EOL> self . cfg = cfg <EOL> self . workdir_base = self . cfg . testscase_tmp_dir <EOL> self . program = program <EOL> self . killprocname = killprocname <EOL> self . backtrace_lines = backtrace_lines <EOL> self . crash_base_dir = crashers_dir <EOL> self . seednum = seednum <EOL> self . range = range <EOL> self . exclude_unmapped_frames = cfg . exclude_unmapped_frames <EOL> self . set_debugger_template ( '<STR_LIT>' ) <EOL> self . keep_uniq_faddr = keep_faddr <EOL> self . cmdargs = None <EOL> self . is_crash = False <EOL> self . signature = None <EOL> self . faddr = None <EOL> self . pc = None <EOL> self . result_dir = None <EOL> def __exit__ ( self , etype , value , traceback ) : <EOL> self . clean_tmpdir ( ) <EOL> def set_debugger_template ( self , option = '<STR_LIT>' ) : <EOL> if host_info . is_linux ( ) : <EOL> dbg_template_name = '<STR_LIT>' % ( registration . debugger , option ) <EOL> self . debugger_template = os . path . join ( self . cfg . debugger_template_dir , dbg_template_name ) <EOL> logger . debug ( '<STR_LIT>' , self . debugger_template ) <EOL> if not os . path . exists ( self . debugger_template ) : <EOL> raise CrashError ( '<STR_LIT>' % self . debugger_template ) <EOL> def update_crash_details ( self ) : <EOL> Crash . update_crash_details ( self ) <EOL> self . cmdargs = self . cfg . get_command_args_list ( self . fuzzedfile . path ) <EOL> self . is_crash = self . confirm_crash ( ) <EOL> if self . is_crash : <EOL> self . signature = self . get_signature ( ) <EOL> self . pc = self . dbg . registers_hex . get ( self . dbg . pc_name ) <EOL> self . result_dir = self . get_result_dir ( ) <EOL> self . debugger_missed_stack_corruption = self . dbg . debugger_missed_stack_corruption <EOL> self . total_stack_corruption = self . dbg . total_stack_corruption <EOL> self . pc_in_function = self . dbg . pc_in_function <EOL> self . faddr = self . dbg . faddr <EOL> logger . debug ( '<STR_LIT>' , self . signature ) <EOL> logger . debug ( '<STR_LIT>' , self . pc ) <EOL> logger . debug ( '<STR_LIT>' , self . result_dir ) <EOL> else : <EOL> self . delete_files ( ) <EOL> return self . is_crash <EOL> def get_debug_output ( self , outfile_base ) : <EOL> global debugger <EOL> if not debugger : <EOL> debugger = registration . get ( ) <EOL> logger . debug ( '<STR_LIT>' , debugger ) <EOL> logger . debug ( '<STR_LIT>' , <EOL> self . debugger_template , outfile_base ) <EOL> debugger_obj = debugger ( self . program , <EOL> self . cmdargs , <EOL> outfile_base , <EOL> self . debugger_timeout , <EOL> self . killprocname , <EOL> template = self . debugger_template , <EOL> exclude_unmapped_frames = self . exclude_unmapped_frames , <EOL> keep_uniq_faddr = self . keep_uniq_faddr <EOL> ) <EOL> self . dbg = debugger_obj . go ( ) <EOL> def confirm_crash ( self ) : <EOL> self . get_debug_output ( self . fuzzedfile . path ) <EOL> if not self . dbg : <EOL> raise CrashError ( '<STR_LIT>' ) <EOL> logger . debug ( '<STR_LIT>' , self . dbg . is_crash , self . dbg . is_assert_fail ) <EOL> if self . cfg . savefailedasserts : <EOL> return self . dbg . is_crash <EOL> else : <EOL> return self . dbg . is_crash and not self . dbg . is_assert_fail <EOL> def __repr__ ( self ) : <EOL> as_list = [ '<STR_LIT>' % ( k , v ) for ( k , v ) in self . __dict__ . items ( ) ] <EOL> return str ( '<STR_LIT:\n>' . join ( as_list ) ) <EOL> def get_signature ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . signature : <EOL> self . signature = self . dbg . get_crash_signature ( self . backtrace_lines ) <EOL> if self . signature : <EOL> logger . debug ( "<STR_LIT>" , self . signature ) <EOL> else : <EOL> raise CrashError ( '<STR_LIT>' ) <EOL> if self . dbg . total_stack_corruption : <EOL> analyzer_instance = pin_calltrace . Pin_calltrace ( self . cfg , self ) <EOL> try : <EOL> analyzer_instance . go ( ) <EOL> except AnalyzerEmptyOutputError : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> return self . signature <EOL> calltrace = Calltracefile ( analyzer_instance . outfile ) <EOL> pinsignature = calltrace . get_crash_signature ( self . backtrace_lines * <NUM_LIT:10> ) <EOL> if pinsignature : <EOL> self . signature = pinsignature <EOL> return self . signature <EOL> def _verify_crash_base_dir ( self ) : <EOL> if not self . crash_base_dir or not os . path . exists ( self . crash_base_dir ) : <EOL> raise CrashError ( '<STR_LIT>' ) <EOL> def get_result_dir ( self ) : <EOL> assert self . crash_base_dir <EOL> assert self . signature <EOL> self . _verify_crash_base_dir ( ) <EOL> self . result_dir = os . path . join ( self . crash_base_dir , self . signature ) <EOL> return self . result_dir <EOL> def get_logger ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . logger = logging . getLogger ( self . signature ) <EOL> if len ( self . logger . handlers ) == <NUM_LIT:0> : <EOL> assert os . path . exists ( self . result_dir ) <EOL> logger . debug ( '<STR_LIT>' , self . result_dir , self . signature ) <EOL> logfile = '<STR_LIT>' % self . signature <EOL> logger . debug ( '<STR_LIT>' , logfile ) <EOL> logpath = os . path . join ( self . result_dir , logfile ) <EOL> logger . debug ( '<STR_LIT>' , logpath ) <EOL> hdlr = logging . FileHandler ( logpath ) <EOL> self . logger . addHandler ( hdlr ) <EOL> return self . logger </s>
