Your IP : 172.28.240.42


Current Path : /usr/share/apport/testsuite/
Upload File :
Current File : //usr/share/apport/testsuite/test_signal_crashes.pyc


Yc	@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZ
dZdZdZdddddd	d
ddg	Zejje
jjZd
ejfdYZedjjZeddkrHejjdejdnedj dZ!e
j"j#rejjdejdnej$dS(iNs/usr/bin/yest	coreutilstProblemTypetCoreDumptDatetExecutablePathtProcCmdlinetProcEnvirontProcMapstSignalt
UserGroupstTc
BseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Ze
jejdejdd
Ze
jejdejddZdZdZdZdZdZdZe
jejdkddZe
jejjdde
jejdkddZe
jejdkddZ e
jejdkddZ!e"e#e$d gdZ&e#e'e(j)e#de$d d gd	Z*dZ+RS(!cCstj|_|jtjd<tj|_tjjtrWtj	ttdnt
jt
jd	tj
dtjjtjjdtjddtjf|_dS(
NtAPPORT_REPORT_DIRs.apporttestiis/tmps%s.%i.crasht/t_(ii(ttempfiletmkdtempt
report_dirtostenvirontworkdirtpathtexiststifpathtrenametresourcet	setrlimittRLIMIT_COREtchdirtjointapportt	fileutilsttest_executabletreplacetgetuidttest_report(tself((s2/usr/share/apport/testsuite/test_signal_crashes.pytsetUps
cCstj|jtj|jtjjtrBtjtntd}tjj|rqtj	|tntjj|j
rtjj
|j
n|jtjjgdS(Ns.apporttest(tshutiltrmtreeRRRRRRtunlinkRR"RRt
delete_reporttassertEqualtget_all_reports(R#torig_ignore_file((s2/usr/share/apport/testsuite/test_signal_crashes.pyttearDown.s
cCs|j}zqtjtt|ddgdtdtjdtj}|jj|j	dks|t
|jjWdt
j|dt
j|dX|j|jgdS(	s)empty core dumps do not generate a reportt42t0t	close_fdststdintstderriNi	(tcreate_test_processt
subprocesstPopentapport_pathtstrtTruetPIPER0tclosetwaittAssertionErrorR1treadRtkilltwaitpidR)tget_temp_all_reports(R#t	test_proctapp((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_empty_core_dump>s
+c	Cs9|j|jtjj|jgtj|j}|jtj|j	dd|jtj|j}|j||dtjj
|j|jtj|j}|j||dtj}|j
t|j|jttjt|jd|j|dt|j|dt|j|dd	tjd
ddd
ddddddddddddddg}xJ|djD]8}|jdd\}}|j||kd|qWx4|d jD]"}|jtj|jd!qW|jd"|d kd#d$S(%sreport generation with apportisreport has correct permissionss.original unseen report did not get overwrittens%original seen report gets overwrittensreport has required fieldsRRRs%itSHELLtPATHtLANGUAGEtLANGtLC_CTYPEt
LC_COLLATEtLC_TIMEt
LC_NUMERICtLC_MONETARYtLC_MESSAGEStLC_PAPERtLC_NAMEt
LC_ADDRESStLC_TELEPHONEtLC_MEASUREMENTtLC_IDENTIFICATIONtLOCPATHtTERMRt=is1report contains sensitive environment variable %sR	itroots/collected system groups are not those from rootN(tdo_crashR)RRR*R"RtstattS_IMODEtst_modetmark_report_seentassertNotEqualtReporttloadtopent
assertTruetsettrequired_fieldstissubsettkeysRtsignaltSIGSEGVt
splitlinestsplitt
assertLesstgrptgetgrnamtgr_gidtassertFalse(	R#tsttst2tprtallowed_varstltktvtg((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_apportMs>


$ cCs|j}|jtd}z8tjtt|ddgdtdtjdtj}tj	dtjtt|ddgdtdtjdtj}d}x7|d	kr|j
rPntj	d
|d8}qW|j|d	d|j|j
d
|j
j|j
jd|j
j|j|jd	|jjWdtj|dtj|d	tj|dtj|d	XdS(s)only one apport instance is ran at a times/bin/ddR-R.R/R0R1g?i2ig?is-second apport instance terminates immediatelys&first apport instance is still runningtbooNi	(R2tFalseR3R4R5R6R7R8ttimetsleeptpollt
assertGreaterRmR0R9twriteR)R:R1R<RR=R>(R#R@t
test_proc2RAtapp2ttimeout((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_parallel_crash|s0



&cCstjj|jd}tjj|jd}tj|||j}z|tjtt	|ddgdt
dtjdtj}|jj
d|jj|j|jd	|jjWd
tj|dtj|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.lockt0wnedR-R.R/R0R1RwiNi	(RRRRtsymlinkR2R3R4R5R6R7R8R0R}R9R\R:R1R<R=R>R)R?RmR(R#tlockpathttrappathR@RA((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_lock_symlinks
&c
Cstjj|jd}t|d2}ttd}|j|jWdQXWdQXtj|d|j	d||j
tjj
gdS(s*unpackaged binaries do not create a reporttmybintwbtrbNitcommand(RRRRR_RR}R<tchmodRWR)RRR*(R#t	local_exetdesttsrc((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_unpackaged_binaryscCstjj|jd}t|d}|jdWdQXtj|d|jd||jt	j
jgtj|j|jdd|jt	j
jgdS(s)unpackaged scripts do not create a reporttmyscripttws#!/bin/sh
kill -SEGV $$NiRs
./myscript(
RRRRR_R}RRWR)RRR*R(R#Rtf((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_unpackaged_scriptscCs0|jdtj|jtjjgdS(sapport ignores SIGQUITtsigN(RWRetSIGQUITR)RRR*(R#((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_ignore_sigquitscCstjj|jd}t|d}|jdWdQXtj|d|jdtd|dd	tjjt	j
jd
tj}t	j
}|jt||j|dd|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_runningRRzis_usr_bin_perl.%i.crashRs
/usr/bin/perltInterpreterPath(RRRRR_R}RRWRxRRRR!R]R^R)RmR((R#RRtleakRp((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(tsysR1R}tflushRWRRtget_new_reportsR[R"R|Ri(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
d|j
t|jttjt|jstdS(s$core dump works for non-writable cwds/runis	/run/coreN(ii(RRRRRRWRR]R`RRR"RmR^R_RaRbRcRdR;(R#Rp((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_nonwritable_cwds

cCs?tjdd\}}|jtj|ttd}tj||jWdQXtj	|tj
|dtjdtj
tjd|jtd|d	ttjj}|jt|d
|d}tj|}|jtj|jdd
|j|jdd|jtjjgdS(s5no core file for non-readable exe in non-writable cwdtdirs/var/tmpRNiIs/runiRtexpect_corefileiiisreport has correct permissionssreport has correct owner(ii(Rtmkstempt
addCleanupRR'R_RR}R<R9RRRRRRWR7RxRRtget_new_system_reportsR)tlenRXRYRZtst_uidR*(R#tfdtmyexeRRtreportRn((s2/usr/share/apport/testsuite/test_signal_crashes.pyt$test_nonwritable_cwd_nonreadable_exes 	


cCstjtjd
|jdtdt|jtjjgtjtjd|jdt|jtjjgtjj	|j
tjtjd|jdtdtj
|jtjj|j
gtjj	|j
tjtjd
|jdtdtj
|jtjj|j
gtjj	|j
tjtjd|jdtdtdtjtjj	|j
tjtjd|jdtdtjtjj	|j
tjtjd|jdtdtjdtj
tjj	|j
tjtjd|jdtdtjdtj
tjj	|j
|jdtd	S(s8packaged executables create core dumps on proper ulimitsiitexpect_coredumpRi
i'texpect_corefile_ownerRN(ii(i
i(i'i(ii(ii(i
i(i'i(ii(RRRRWRxR)RRR*R(R"R7RtgeteuidRetSIGABRT(R#((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_core_dump_packaged3s8%%cCstjj|jd}t|d2}ttd}|j|jWdQXWdQXtj|dt	j
t	jd|jdt
d	t
d
||jtjjgt	j
t	jd|jtjjgt	j
t	jd|jd	td
||jtjjgt	j
t	jd|jd	td
||jtjjgt	j
t	jd|jdt
d	t
d
|d
tj|jtjjgt	j
t	jd|jd	t
d
|d
tj|jtjjgt	j
t	jd|jd	td
|d
tj|jtjjgt	j
t	jd|jd	td
|d
tj|jtjjgdS(s:unpackaged executables create core dumps on proper ulimitsRRRNiiiRRRi
i'R(ii(i
i(i'i(ii(ii(i
i(i'i(ii(RRRRR_RR}R<RRRRRWRxR)RRR*R7ReR(R#RRR((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_core_dump_unpackagedXs8%cCs&t|jdd}|jdWdQXtjtjd|j}tj|t	j
x3trytj|jPWqat
k
rqaXqaWtj|jd|jtj|dtjdtdd	}|j}WdQX|jd
||jt|dtjddS(
scannot inject core files.injectRs\ProblemType: Crash
CoreDump: base64
 H4sICAAAAAAC/0NvcmVEdW1wAA==
 Yywoz0tNAQBl1rhlBgAAAA==
Niig?tcoreRtpwnedi'(ii(R_R"R}RRRR2RR=ReRfR7R'tOSErrorRR>RyRzR<tassertNotInR|R(R#RtpidR((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_core_file_injection|s(
	

c
	CsPtj}td}|j|WdQXt|djdt|djd}|d:}d}|j}ztj	t
t|ddgd	td
tj
dtj
}dd
}x|dkrQ|d@dkrtjjdtjjny|jj|Wn,tk
rC}|jtjkr=PqDnX|d8}qW|jj|j|jd|jjd}Wdtj|dtj|dX|j}|jt|dtj}	t|d}|	j|WdQXtj|d|j|	dd|j|	dt |j!d|	kdS(s.core dumps are capped on available memory sizes
/proc/meminfoNtMemFreeitCachediR-R.R/R0R1t iit.ii	RRR("RR]R_R^tlongRhtNoneR2R3R4R5R6R7R8RR1R}RR0tIOErrorterrnotEPIPER9R)R:R<RR=R>R?RR'RRm(
R#trRttotalmbR@RAtonembteRRp((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_limit_sizesH2


"
cCs|jtjj}|jt|dtj}t|d}|j|WdQXt	j
|d|j|j|jtjjgdS(signoring executablesiiN(RWRRR*R)RR]R_R^RR'tmark_ignore(R#RRpR((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_ignores


c	Cswtjdd\}}zJtt}tj||jWdQXtj|tj|dt	j
dz|jd|}t	j
dtj|dtjtt|dd	gd
tdtjdtj}|jjd
|jj|jjj}|j|jd|Wdtj|dtj|dX|j|jgWdtj|XdS(s<ignores executables which got modified after process startedRs/var/tmpNiiRg?R-R.R/R0R1Rwii	(RRR_RRR}R<R9RRyRzR2tutimeRR3R4R5R6R7R8R0R1tdecodeR\R:R=R>R)R?R'(R#RRRR@RAterr((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_modify_after_starts*



is!this test needs to be run as rootcCs#tjdd\}}|jtj|ttd}tj||jWdQXtj	|tj
|dtjtj
d|jd|dd	tjj}|jt|d
|d}tj|}tj||jtj|jdd
|j|jdddS(s5report generation for setuid program which stays rootRs/var/tmpRNi	iRtuidiiiisreport has correct permissionssreport has correct owner(ii(RRRRR'R_RR}R<R9RRRRRWRRR*R)RRXRYRZR(R#RRRRRRn((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_setuid_keeps


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(RRRRWRRR*R)RRRXR'RYRZR(R#RRRn((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_setuid_drop,s

cCstjdd\}}|jtj|ttd}tj||jWdQXtj	|tj
|dtjtj
d|jd|dtd	d
|jtjjgdS(s/report generation for unpackaged setuid programRs/tmpRNi	iRRRi(ii(RRRRR'R_RR}R<R9RRRRRWRxR)RRR*(R#RRR((s2/usr/share/apport/testsuite/test_signal_crashes.pyttest_crash_setuid_unpackaged@s
cCs6tjdd\}}|jtj|ttd}tj||jWdQXtj	|tj
|dtjdtj
tjd|jd|d	td
dtjj}|jt|d|d
}tj|}tj||jtj|jdd|j|jd
ddS(sDreport generation and core dump for setuid program, non-writable cwdRs/var/tmpRNi	s/runiRRRiiiisreport has correct permissionssreport has correct owner(ii(RRRRR'R_RR}R<R9RRRRRRWRxRRR*R)RRXRYRZR(R#RRRRRRn((s2/usr/share/apport/testsuite/test_signal_crashes.pyt!test_crash_setuid_nonwritable_cwdVs 



cCs9tj|tjs%t|d|rUtjd|gdksUtdntj}|dkr|dk	rtj|ntj	tj
dtjtj
jtjjtjtj||g|tstd|nx-dt
d	|jkr'tjd
qWtjd|S(
s\Spawn test_executable.

        Wait until it is fully running, and return its PID.
        s is not executabletpidofis$no running test executable processesis	/dev/nullsCould not execute ttest_signals/proc/%i/cmdlineg?g333333?N(RtaccesstX_OKR;R3tcalltforkRtsetuidtdup2R_tO_WRONLYRtstdouttfilenoR0R9tsetsidtexecvRxR<RyRz(tklassRRRRR((s2/usr/share/apport/testsuite/test_signal_crashes.pyR2ys %*(


c
Cs|jtjjddtj|j||d|d|	}
|dkr`tj|ntj|
|tj	|
dd}|jtj
|d|jtj|d|j
tj|||j
tj|dd	|j
tj||d
d}xR|dkrctjdd
dgdtjdkrIPntjd|d8}qW|j|d|r|j
tjd|gddn|r|jtjjddztjd}
|j
tj|
jdd|dk	r|j
|
j|dntjdddd|dgdtjdtj}|j\}}|j
|jd|j}|j|dkp|jd|WdtjdXn|jtjjdddS(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 firstRRiis"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$no running test executable processessleaves wanted core fileis!core file has correct permissionsscore file has correct ownertgdbs--batchs--extbtR1ttwarningNs"leaves unexpected core file behind( RmRRRtgetcwdR2RyRzR=R>t	WIFEXITEDR`tWIFSIGNALEDR)t	WCOREDUMPtWSTOPSIGtWTERMSIGR3RR8R|RXRYRZRRR4tcommunicatet
returncodetstript
startswithR'(R#RRRRRzRRRRRtresultRRnRtoutR((s2/usr/share/apport/testsuite/test_signal_crashes.pyRWsJ&'

)cCs:tjj}|jtj_tjj}|tj_|S(s8Call apport.fileutils.get_all_reports() for our temp dir(RRRR*(R#told_dirR((s2/usr/share/apport/testsuite/test_signal_crashes.pyR?s
N(,t__name__t
__module__R$R,RBRvRRRRRRRtunittesttskipIfRRtW_OKRRRRRRRRRRt
skipUnlessRRRRRtclassmethodR7RRR2RxReRfRWR?(((s2/usr/share/apport/testsuite/test_signal_crashes.pyR
s@				/	'						*
*#	%	$	*	4		$'*''#9s/proc/sys/kernel/core_patternit|sPkernel crash dump helper is not active; please enable before running this test.
isEPlease remove all crash reports from /var/crash/ for this test suite
(%RR%RR3ReRyRXRRRRjRtapport.fileutilsRRttest_packagettest_sourceRbRt
expanduserRt_ignore_fileRtTestCaseR
R_R<Rtcore_patternR1R}texitRhR5RR*tmain(((s2/usr/share/apport/testsuite/test_signal_crashes.pyt<module>
s(`0