1
0
Fork 0
dnf-plugins-core/SOURCES/0035-Fix-issue-with-invalid...

50 lines
2.1 KiB
Diff
Raw Blame History

diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py
index 66d0e0f..7bbf92f 100644
--- a/plugins/needs_restarting.py
+++ b/plugins/needs_restarting.py
@@ -73,7 +73,7 @@ def list_opened_files(uid):
try:
if uid is not None and uid != owner_uid(smaps):
continue
- with open(smaps, 'r') as smaps_file:
+ with open(smaps, 'r', errors='replace') as smaps_file:
lines = smaps_file.readlines()
except EnvironmentError:
logger.warning("Failed to read PID %d's smaps.", pid)
diff --git a/tests/test_needs_restarting.py b/tests/test_needs_restarting.py
index 7b629b4..49472bc 100644
--- a/tests/test_needs_restarting.py
+++ b/tests/test_needs_restarting.py
@@ -1,3 +1,4 @@
+# coding: utf-8
# Copyright (C) 2014 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
@@ -24,6 +25,7 @@ from unittest.mock import patch, Mock
import dbus
import needs_restarting
import tests.support
+import tempfile
DEL_FILE = '3dcf000000-3dcf032000 r-xp 00000000 08:02 140759 ' \
' /usr/lib64/libXfont.so.1.4.1;5408628d (deleted)'
@@ -58,6 +60,18 @@ class NeedsRestartingTest(tests.support.TestCase):
patch( "dbus.bus.BusConnection.__new__", side_effect=dbus.DBusException("Never should hit this exception if mock above works")):
self.assertIsNone(func(1234))
+
+ def test_list_opened_files_garbage_filename(self):
+ tempObj = tempfile.NamedTemporaryFile()
+ tempFile = tempObj.name
+ with open(tempFile, 'wb') as bogusFile:
+ bogusFile.write(b'151e7f7b7000-151e7f7b8000 r--p 00006000 fd:01 14744 /usr/lib64/lib\xe5Evil-13.37.so')
+ smaps = [[1234,tempObj.name]]
+ with patch("needs_restarting.list_smaps", return_value=smaps):
+ ofiles = list(needs_restarting.list_opened_files(None));
+ self.assertEqual(ofiles[0].presumed_name, '/usr/lib64/lib<69>Evil-13.37.so')
+
+
class OpenedFileTest(tests.support.TestCase):
def test_presumed_name(self):
ofile = needs_restarting.OpenedFile(