mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-08 22:36:48 +02:00
fix proc signature for pid_stat so hack comm names with parenthesis are handled correctly.
This commit is contained in:
@ -201,7 +201,7 @@ def parse(
|
||||
pid_mountinfo_p = re.compile(r'^\d+ \d+ \d+:\d+ /.+\n')
|
||||
pid_numa_maps_p = re.compile(r'^[a-f0-9]{12} default [^\n]+\n')
|
||||
pid_smaps_p = re.compile(r'^[0-9a-f]{12}-[0-9a-f]{12} [rwxsp\-]{4} [0-9a-f]{8} [0-9a-f]{2}:[0-9a-f]{2} \d+ [^\n]+\nSize:\s+\d+ \S\S\n')
|
||||
pid_stat_p = re.compile(r'^\d+ \(.{1,15}\) \S \d+ \d+ \d+ \d+ -?\d+ (?:\d+ ){43}\d+$', re.DOTALL)
|
||||
pid_stat_p = re.compile(r'^\d+ \(.+\) \S \d+ \d+ \d+ \d+ -?\d+ (?:\d+ ){43}\d+$', re.DOTALL)
|
||||
pid_statm_p = re.compile(r'^\d+ \d+ \d+\s\d+\s\d+\s\d+\s\d+$')
|
||||
pid_status_p = re.compile(r'^Name:\t.+\nUmask:\t\d+\nState:\t.+\nTgid:\t\d+\n')
|
||||
|
||||
|
1
tests/fixtures/linux-proc/pid_stat_hack
vendored
Normal file
1
tests/fixtures/linux-proc/pid_stat_hack
vendored
Normal file
@ -0,0 +1 @@
|
||||
2001 (bad) S 1 2 3 4 5) S 1888 2001 1888 34816 2001 4202496 428 0 0 0 0 0 0 0 20 0 1 0 75513 115900416 297 18446744073709551615 4194304 5100612 140737020052256 140737020050904 140096699233308 0 65536 4 65538 18446744072034584486 0 0 17 0 0 0 0 0 0 7200240 7236240 35389440 140737020057179 140737020057223 140737020057223 140737020059606 0
|
1
tests/fixtures/linux-proc/pid_stat_hack.json
vendored
Normal file
1
tests/fixtures/linux-proc/pid_stat_hack.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"pid":2001,"comm":"bad) S 1 2 3 4 5","state":"S","ppid":1888,"pgrp":2001,"session":1888,"tty_nr":34816,"tpg_id":2001,"flags":4202496,"minflt":428,"cminflt":0,"majflt":0,"cmajflt":0,"utime":0,"stime":0,"cutime":0,"cstime":0,"priority":20,"nice":0,"num_threads":1,"itrealvalue":0,"starttime":75513,"vsize":115900416,"rss":297,"rsslim":18446744073709551615,"startcode":4194304,"endcode":5100612,"startstack":140737020052256,"kstkeep":140737020050904,"kstkeip":140096699233308,"signal":0,"blocked":65536,"sigignore":4,"sigcatch":65538,"wchan":18446744072034584486,"nswap":0,"cnswap":0,"exit_signal":17,"processor":0,"rt_priority":0,"policy":0,"delayacct_blkio_ticks":0,"guest_time":0,"cguest_time":0,"start_data":7200240,"end_data":7236240,"start_brk":35389440,"arg_start":140737020057179,"arg_end":140737020057223,"env_start":140737020057223,"env_end":140737020059606,"exit_code":0,"state_pretty":"Sleeping in an interruptible wait"}
|
@ -206,6 +206,9 @@ class MyTests(unittest.TestCase):
|
||||
'pid_stat_w_space_and_nl_in_comm': (
|
||||
'fixtures/linux-proc/pid_stat_w_space_and_nl_in_comm',
|
||||
'fixtures/linux-proc/pid_stat_w_space_and_nl_in_comm.json'),
|
||||
'proc_pid_stat_hack': (
|
||||
'fixtures/linux-proc/pid_stat_hack',
|
||||
'fixtures/linux-proc/pid_stat_hack.json'),
|
||||
'proc_pid_statm': (
|
||||
'fixtures/linux-proc/pid_statm',
|
||||
'fixtures/linux-proc/pid_statm.json'),
|
||||
|
@ -19,7 +19,10 @@ class MyTests(unittest.TestCase):
|
||||
'fixtures/linux-proc/pid_stat.json'),
|
||||
'pid_stat_w_space_and_nl_in_comm': (
|
||||
'fixtures/linux-proc/pid_stat_w_space_and_nl_in_comm',
|
||||
'fixtures/linux-proc/pid_stat_w_space_and_nl_in_comm.json')
|
||||
'fixtures/linux-proc/pid_stat_w_space_and_nl_in_comm.json'),
|
||||
'pid_stat_hack': (
|
||||
'fixtures/linux-proc/pid_stat_hack',
|
||||
'fixtures/linux-proc/pid_stat_hack.json')
|
||||
}
|
||||
|
||||
for file, filepaths in fixtures.items():
|
||||
@ -49,6 +52,13 @@ class MyTests(unittest.TestCase):
|
||||
self.assertEqual(jc.parsers.proc_pid_stat.parse(self.f_in['pid_stat_w_space_and_nl_in_comm'], quiet=True),
|
||||
self.f_json['pid_stat_w_space_and_nl_in_comm'])
|
||||
|
||||
def test_proc_pid_stat_hack(self):
|
||||
"""
|
||||
Test '/proc/<pid>/stat' with evil command hack
|
||||
"""
|
||||
self.assertEqual(jc.parsers.proc_pid_stat.parse(self.f_in['pid_stat_hack'], quiet=True),
|
||||
self.f_json['pid_stat_hack'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user