diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-16 01:22:29 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-16 01:22:29 +0000 |
| commit | 005ded7710edd9e18e9857469ee8d8fb8f0ad595 (patch) | |
| tree | a741c9361cda3ce9791237be0fe99c86b079d954 | |
| parent | aa89d8b27a86abc1ba84133c655a49fa3ccda798 (diff) | |
| parent | ea78eecbd275fa7466e56d6eb0dc7a3c60f5b640 (diff) | |
| download | oslo-005ded7710edd9e18e9857469ee8d8fb8f0ad595.tar.gz oslo-005ded7710edd9e18e9857469ee8d8fb8f0ad595.tar.xz oslo-005ded7710edd9e18e9857469ee8d8fb8f0ad595.zip | |
Merge "Update KillFilter to stop at '\0' for readlink() function."
| -rw-r--r-- | openstack/common/rootwrap/filters.py | 4 | ||||
| -rw-r--r-- | tests/unit/test_rootwrap.py | 12 |
2 files changed, 16 insertions, 0 deletions
diff --git a/openstack/common/rootwrap/filters.py b/openstack/common/rootwrap/filters.py index 58121cb..ae7c62c 100644 --- a/openstack/common/rootwrap/filters.py +++ b/openstack/common/rootwrap/filters.py @@ -194,6 +194,10 @@ class KillFilter(CommandFilter): return False try: command = os.readlink("/proc/%d/exe" % int(args[1])) + # NOTE(yufang521247): /proc/PID/exe may have '\0' on the + # end, because python doen't stop at '\0' when read the + # target path. + command = command.split('\0')[0] # NOTE(dprince): /proc/PID/exe may have ' (deleted)' on # the end if an executable is updated or deleted if command.endswith(" (deleted)"): diff --git a/tests/unit/test_rootwrap.py b/tests/unit/test_rootwrap.py index ea6ccbb..5a5d9ca 100644 --- a/tests/unit/test_rootwrap.py +++ b/tests/unit/test_rootwrap.py @@ -134,6 +134,18 @@ class RootwrapTestCase(utils.BaseTestCase): self.stubs.Set(os, 'readlink', fake_readlink) self.assertTrue(f.match(usercmd)) + def test_KillFilter_upgraded_exe(self): + """Makes sure upgraded exe's are killed correctly""" + # See bug #1179793. + def fake_readlink(blah): + return '/bin/commandddddd\0\05190bfb2 (deleted)' + + f = filters.KillFilter("root", "/bin/commandddddd") + usercmd = ['kill', 1234] + + self.stubs.Set(os, 'readlink', fake_readlink) + self.assertTrue(f.match(usercmd)) + def test_ReadFileFilter(self): goodfn = '/good/file.name' f = filters.ReadFileFilter(goodfn) |
