P[c @sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl ZdZdZdZdeeefdeeefdeeefdeeefgZddd d d d d ddg ZejdZeek rEejd=nejjejjZeek ryeejdRR?R@(R%RBt test_proc2RCtapp2ttimeout((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_parallel_crashs4 ! !     "cCs)tjj|jd}tjj|jd}tj|||j}ztjtt |dddgdtj dtj }|j j d|j j |j|jd |jj|jj Wd tj|d tj|d X|j|jg|jtjj|d S( sexisting .lock file as dangling symlink does not create the file This would be a vulnerability, as users could overwrite system files. s.lockt0wnedR1R R2R3R4RiNi (RRRRtsymlinkR5R6R7R8R9R:R3RR;RcR<R4R>R?R@R,RARtR(R%tlockpathttrappathRBRC((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_lock_symlinks ! "c Cstjj|jd}t|d2}ttd}|j|jWdQXWdQXtj|d|j d||j t j j gdS(s*unpackaged binaries do not create a reporttmybintwbRENitcommand(RRRRReR!RR>tchmodR\R,RR R+(R%t local_exetdesttsrc((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_unpackaged_binaryscCstjj|jd}t|d}|jdWdQXtj|d|jd||jt j j gtj |j|jdd|jt j j gdS(s)unpackaged scripts do not create a reporttmyscripttws#!/bin/sh kill -SEGV $$NiRs ./myscript( RRRRReRRR\R,RR R+R(R%RRx((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_unpackaged_scriptscCs0|jdtj|jtjjgdS(sapport ignores SIGQUITtsigN(R\RltSIGQUITR,RR R+(R%((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_ignore_sigquitscCstjj|jd}t|d}|jdWdQXtj|d|jdtd|dd tjjt j j d tj }t j }t|d }|j|WdQX|j|d d |jd|kt j j|dS(s2existence of user-inaccessible files does not leakRRs_#!/usr/bin/perl system("mv $0 $0.exe"); system("ln -sf /etc/shadow $0"); $0="..$0"; sleep(10); Nit check_runningRRis_usr_bin_perl.%i.crashRERs /usr/bin/perltInterpreterPath(RRRRReRRR\RRR RR#RdRfR,RtR*(R%RRxtleakRw((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_leak_inaccessible_filess cCsd}xq|dkrytjjd|tjj|jtjj}|sYPntjj|j |d7}q W|j |dd|j |dddS(s limitation of crash report floodiis%i is gets at least 2 repeated crashess1stops flooding after less than 7 repeated crashesN( tsysR4RtflushR\RR tget_new_reportsRbR$RRp(R%tcounttreports((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_flood_limits  s/runs!this test needs to be run as usercCstjdtjtjd|jtj}|jtj j |j |j tj j dt |j d}|j|WdQXttjt|jstdS(s$core dump works for non-writable cwds/runis /run/coreREN(ii(RRRRRR\RRdRgRRR$RtReRfRhRiRjRkR=(R%RwRx((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_nonwritable_cwd$s   cCs?tjdd\}}|jtj|ttd}tj||jWdQXtj |tj |dtj dt j t jd|jtd|d ttjj}|jt|d |d }tj|}|jtj|jd d |j|jd d|jtjjgdS(s5no core file for non-readable exe in non-writable cwdtdirs/var/tmpRENiIs/runiRtexpect_corefileiiisreport has correct permissionssreport has correct owner(ii(Rtmkstempt addCleanupRR)ReR!RR>R;RRRRRR\tTrueRRR tget_new_system_reportsR,tlenR]R^R_R`R+(R%tfdtmyexeRxRtreportRu((s2/usr/share/apport/testsuite/test_signal_crashes.pyt$test_nonwritable_cwd_nonreadable_exe2s    c CsKxtjtjfD]}xtD]\}}}}tjtj|df|jd|d|dtj d||r|j t j j |jg|j|jt j j|jq |j t j j gq W|jdtt j j|jqWtjtjd|jdtdtj|j t j j gdS( s8packaged executables create core dumps on proper ulimitsitexpect_coredumpRtexpect_corefile_ownerRi'N(i'i(RlRmtSIGABRTtcore_ulimit_tableRRRR\RRaR,RR R+R$tcheck_report_coredumpR*RR(R%Rtkbtexp_sigtexp_filet exp_report((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_core_dump_packagedUs" c Cstjj|jd}t|d2}ttd}|j|jWdQXWdQXtj|dxt j t j t j fD]}xzt D]r\}}}}tjtj|df|jd|d|d tjd |d ||jtjjgqWqWdS( s:unpackaged executables create core dumps on proper ulimitsRRRENiiRRRRR(RRRRReR!RR>RRlRmRRRRRRR\RaR,RR R+( R%RRRRRRRR((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_core_dump_unpackagedps cCs0t|jdd}|jdWdQXtjtjd |j}tj|t j x3t rytj |jPWqat k rqaXqaWtj|jd|jtj|dtjdtjtdd }|j}WdQX|jd ||jt|d tj ddS( scannot inject core files.injectRs\ProblemType: Crash CoreDump: base64 H4sICAAAAAAC/0NvcmVEdW1wAA== Yywoz0tNAQBl1rhlBgAAAA== Niig?tcoreREtpwnedi'(ii(ReR$RRRRR5RR?RlRmRR)tOSErrorRR@RRtsyncR>t assertNotInRR(R%RxtpidR((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_core_file_injections*      c Csftj}tdd}|j|WdQXt|djdt|djd}t|d}d}|j}ztj t t |dd d gd tj d tj }d d}x|dkrW|d@dkrt jjdt jjny|jj|Wn,tk rI}|jtjkrCPqJnX|d8}qW|jj|j|jd|jj|jjd}Wdtj|dtj|dX|j}|jt|dtj} t|dd}| j|WdQXtj|d|j| dd|j| dt|j d| kdS(s.core dumps are capped on available memory sizes /proc/meminfoRENtMemFreeitCachediR1R R2R3R4t iit.ii RRR(!RRdReRftintRotNoneR5R6R7R8R9R:RR4RRR3tIOErrorterrnotEPIPER;R,R<R>RR?R@RARR)R!Rt( R%R/RxttotalmbRBRCtonembteRRw((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_limit_sizesJ 2 !  "    cCs|jtjj}|jt|dtj}t|dd}|j|WdQXt j |d|j |j|jtjjgdS(signoring executablesiiREN( R\RR R+R,RRdReRfRR)t mark_ignore(R%RRwRx((s2/usr/share/apport/testsuite/test_signal_crashes.pyt test_ignores    cCstjdd\}}|jtj|ttd}tj||jWdQXtj |tj |dt j dz|j d|}t j dtj|dtjtt|d d d gd tjd tj}|jjd|jj |jjj}|j|jd||jj Wdtj|dtj|dX|j|jgdS(s<ignores executables which got modified after process startedRs/var/tmpRENiiRg?R1R R2R3R4Rii (RRRRR)ReR!RR>R;RRRR5tutimeRR6R7R8R9R:R3R4tdecodeRcR<R?R@R,RA(R%RRRxRBRCterr((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_modify_after_starts*   ! c Cs|j}tjj|jd}zwtjj}||dRgRtRARRRdRfR)R!( R%RBtlogRRCtoutRRxtloggedRRw((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_logging_files:  !    c Cs|j}ztjj}d|ds4  !    is!this test needs to be run as rootcCs#tjdd\}}|jtj|ttd}tj||jWdQXtj |tj |dt j t j d|jd|dd tjj}|jt|d |d }tj|}tj||jtj|jd d |j|jd ddS(s5report generation for setuid program which stays rootRs/var/tmpRENi iRtuidiiiisreport has correct permissionssreport has correct owner(ii(RRRRR)ReR!RR>R;RRRRR\RR R+R,RR]R^R_R`(R%RRRxRRRu((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_setuid_keepas   s /bin/pingsthis test needs /bin/pingcCstjtjd|jddddgddtjj}|jt|d|d }t j |}t j ||jt j |j d d |j|jd d d S(s5report generation for setuid program which drops rootiRs /bin/pingtargss 127.0.0.1Riiiisreport has correct permissionssreport has correct ownerN(ii(RRRR\RR R+R,RRR]R)R^R_R`(R%RRRu((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_setuid_drop}s  cCstjdd\}}|jtj|ttd}tj||jWdQXtj |tj |dt j t j d |jd|dtd d |jtjjgdS( s/report generation for unpackaged setuid programRs/tmpRENi iRRRi(ii(RRRRR)ReR!RR>R;RRRRR\RR,RR R+(R%RRRx((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_setuid_unpackageds c Cstjjtjjddtjf|_tj tj dt rFt j d}tjd}dtjd<|jddd d d |d gd tdddd|dk r|tjdR;RRRRRR\RRR R+R,RR]R^R_R`(R%RRRxRRRu((s2/usr/share/apport/testsuite/test_signal_crashes.pyt!test_crash_setuid_nonwritable_cwds     cCshtj|tjs%t|d|rUtjd|gdksUtdntj}|dkr|d k rtj|ntj ddtj tj dtj t jjt jjtjtj||g|tstd |nxLtrVt d |}|j}Wd QXd |krRtjd q Pq Wtjd|S(s\Spawn test_executable. Wait until it is fully running, and return its PID. s is not executabletpidofis$no running test executable processesitutf8trapsàäs /dev/nullsCould not execute s/proc/%i/cmdlineNt test_signalg?g333333?(RtaccesstX_OKR=R6tcalltforkRtsetuidtputenvtdup2RetO_WRONLYRRtfilenoR3R;tsetsidtexecvRRR>RR(tklassRRRRRRxtcmdline((s2/usr/share/apport/testsuite/test_signal_crashes.pyR5s*%*   (     c  Cs|jtjjddtj|j||d|d| } |dkr`tj|n| rtj | } t j dddd d || fd | dg}|j |d krtj d n|jdkr |jd| | dfq ntj| |tj| dd}|jtj|d|jtj|d|jtj|||jtj|dd|jtj||dd}xe|dkrt j dddgdt j}|j |jdkrPntjd|d8}qW|j|d|d krUt j dddd dd dgn|r|jt jd|gddndtj}| rd| }n|d7}|r|jtjj|dztj|}|jtj|jdd |d'k r%|j|j |d!nt j d"d#d$d%||gdt jd&t j}|j \}}|j|jd|j!}|j!j"}Wd'tj#|Xnitjj|rytj#|Wn3t$k r}t%j&j'd(|t(|fnX|jd)nd'S(*sGenerate a test crash. This runs command (by default test_executable) in cwd, lets it crash, and checks that it exits with the expected return code, leaving a core file behind if expect_corefile is set, and generating a crash report if expect_coredump is set. If check_running is set (default), this will abort if test_process is already running. Rs-%s/core already exists, please clean up firstRRitsudos-ss /bin/bashs-cs/bin/kill -s %i %ss-us/usr/bin/crontabs stty sanes$Couldn't kill process %s as user %s.is"test process did not exit normallystest process died due to signals%test process was not signaled to stops&test process died due to proper signali2Rs-xRRg?s/usr/bin/pkill -9 -f crontabtmails$no running test executable processess%s/sleaves wanted core fileis!core file has correct permissionsscore file has correct ownertgdbs--batchs--extbtR4Ns*WARNING: cannot clean up core file %s: %s s"leaves unexpected core file behind()RtRRRtgetcwdR5RRRRR6R7RtsystemRtfailR?R@t WIFEXITEDRgt WIFSIGNALEDR,t WCOREDUMPtWSTOPSIGtWTERMSIGR:RRR]R^R_RR`RtstripR)RRR4RR9(R%RRRRRRRRRRRRRR?tresultRRt core_pathRuRRRR((s2/usr/share/apport/testsuite/test_signal_crashes.pyR\s&     !            cCs:tjj}|jtj_tjj}|tj_|S(s8Call apport.fileutils.get_all_reports() for our temp dir(RR RR+(R%told_dirR((s2/usr/share/apport/testsuite/test_signal_crashes.pyRAps   cCstj}t|d}|j|WdQX|jd|k|jt|dd|j|jd|jddk|jdddS( s2Check that given report file has a valid core dumpRENRis #2t StacktraceRsno Stacktrace field( RRdReRfRgRRt add_gdb_infotget(R%t report_pathR/Rx((s2/usr/share/apport/testsuite/test_signal_crashes.pyRys  N(0t__name__t __module__R&R0RDR~RRRRRRRtunittesttskipIfRRtW_OKRRRRRRRRRRRaRt skipUnlessRRRRRRt classmethodRR!RR5RRlRmR\RAR(((s2/usr/share/apport/testsuite/test_signal_crashes.pyR -sN    2 )     **#   + 5  # & #'*'*$'#  Z s/proc/sys/kernel/core_patternit|sPkernel crash dump helper is not active; please enable before running this test. sKPlease remove all crash reports from /var/crash/ for this test suite: %s s s /var/crash(2RR'RR6RlRR]RRRRqRRtapport.fileutilsRR!t test_packaget test_sourceRRRRiRt orig_homeRRRt expanduserRt _ignore_fileRRReRxR>RRtTestCaseR t core_patternR4RtexitRoR8R R+Rtlistdirtmain(((s2/usr/share/apport/testsuite/test_signal_crashes.pyt sP`<        _