From 73cb5444ed2c7a32429ed1e48fe210ec6536fb79 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 14 Dec 2023 13:06:22 -0600 Subject: [PATCH 1/3] re-merge invalid utf-8 patch from 9.2 --- SPECS/dnf-plugins-core.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SPECS/dnf-plugins-core.spec b/SPECS/dnf-plugins-core.spec index 19a3dd1..01a8bdb 100644 --- a/SPECS/dnf-plugins-core.spec +++ b/SPECS/dnf-plugins-core.spec @@ -34,7 +34,7 @@ Name: dnf-plugins-core Version: 4.0.21 -Release: 23%{?dist} +Release: 23%{?dist}.alma.1 Summary: Core Plugins for DNF License: GPLv2+ URL: https://github.com/rpm-software-management/dnf-plugins-core @@ -73,6 +73,7 @@ Patch31: 0031-Fix-boot-time-derivation-for-systems-with-no-rtc.patch Patch32: 0032-Doc-update-for-reposync-RhBug-2132383-2182004.patch Patch33: 0033-Add-fix-and-test-assertion-for-no-systemd-unit-exist.patch Patch34: 0034-Fix-zlib-reboot-requirement-RhBug-2092033.patch +Patch35: 0035-Fix-issue-with-invalid-utf8.patch BuildArch: noarch @@ -849,6 +850,9 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/ %endif %changelog +* Thu Dec 14 2023 Jonathan Wright - 4.0.21-23.alma.1 +- Fix issue with invalid utf-8 chars in needs-restarting rhbz#2212953 + * Tue Jun 27 2023 Jaroslav Rohel - 4.0.21-23 - Add patch: Fix zlib reboot requirement (RhBug:2092033) From 0697c96324eac29bf1c8313817d1e7696fa70522 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 14 Dec 2023 13:12:54 -0600 Subject: [PATCH 2/3] add missing patch file --- .../0035-Fix-issue-with-invalid-utf8.patch | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 SOURCES/0035-Fix-issue-with-invalid-utf8.patch diff --git a/SOURCES/0035-Fix-issue-with-invalid-utf8.patch b/SOURCES/0035-Fix-issue-with-invalid-utf8.patch new file mode 100644 index 0000000..296ecd3 --- /dev/null +++ b/SOURCES/0035-Fix-issue-with-invalid-utf8.patch @@ -0,0 +1,63 @@ +From 7860463eb5ccc844f1d580edd7f12496fb6923b3 Mon Sep 17 00:00:00 2001 +From: Jonathan Wright +Date: Mon, 14 Aug 2023 09:55:12 -0500 +Subject: [PATCH] fixes error with handling invalid utf-8 chars in + needs-restarting + +--- + plugins/needs_restarting.py | 2 +- + tests/test_needs_restarting.py | 13 +++++++++++++ + 2 files changed, 14 insertions(+), 1 deletion(-) + +diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py +index 1fedb73..d8ab0bc 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 0ad70a5..c021e06 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, +@@ -20,8 +21,10 @@ from __future__ import absolute_import + from __future__ import print_function + from __future__ import unicode_literals + ++from unittest.mock import patch + 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)' +@@ -46,6 +49,16 @@ class NeedsRestartingTest(tests.support.TestCase): + self.assertTrue(ofile.deleted) + self.assertEqual(ofile.name, '/usr/lib64/libXfont.so.1.4.1;5408628d') + ++ 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�Evil-13.37.so') ++ + + class OpenedFileTest(tests.support.TestCase): + def test_presumed_name(self): +-- +2.41.0 From e93beac9a085c9f7cbd2245d51fd2e1c72c2198e Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 14 Dec 2023 13:45:01 -0600 Subject: [PATCH 3/3] rebase utf8 fix patch file to build on top of new patches from upstream --- .../0035-Fix-issue-with-invalid-utf8.patch | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/SOURCES/0035-Fix-issue-with-invalid-utf8.patch b/SOURCES/0035-Fix-issue-with-invalid-utf8.patch index 296ecd3..264182e 100644 --- a/SOURCES/0035-Fix-issue-with-invalid-utf8.patch +++ b/SOURCES/0035-Fix-issue-with-invalid-utf8.patch @@ -1,16 +1,5 @@ -From 7860463eb5ccc844f1d580edd7f12496fb6923b3 Mon Sep 17 00:00:00 2001 -From: Jonathan Wright -Date: Mon, 14 Aug 2023 09:55:12 -0500 -Subject: [PATCH] fixes error with handling invalid utf-8 chars in - needs-restarting - ---- - plugins/needs_restarting.py | 2 +- - tests/test_needs_restarting.py | 13 +++++++++++++ - 2 files changed, 14 insertions(+), 1 deletion(-) - diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py -index 1fedb73..d8ab0bc 100644 +index 66d0e0f..7bbf92f 100644 --- a/plugins/needs_restarting.py +++ b/plugins/needs_restarting.py @@ -73,7 +73,7 @@ def list_opened_files(uid): @@ -23,7 +12,7 @@ index 1fedb73..d8ab0bc 100644 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 0ad70a5..c021e06 100644 +index 7b629b4..49472bc 100644 --- a/tests/test_needs_restarting.py +++ b/tests/test_needs_restarting.py @@ -1,3 +1,4 @@ @@ -31,21 +20,19 @@ index 0ad70a5..c021e06 100644 # Copyright (C) 2014 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, -@@ -20,8 +21,10 @@ from __future__ import absolute_import - from __future__ import print_function - from __future__ import unicode_literals - -+from unittest.mock import patch +@@ -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)' -@@ -46,6 +49,16 @@ class NeedsRestartingTest(tests.support.TestCase): - self.assertTrue(ofile.deleted) - self.assertEqual(ofile.name, '/usr/lib64/libXfont.so.1.4.1;5408628d') +@@ -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 @@ -56,8 +43,7 @@ index 0ad70a5..c021e06 100644 + ofiles = list(needs_restarting.list_opened_files(None)); + self.assertEqual(ofiles[0].presumed_name, '/usr/lib64/lib�Evil-13.37.so') + - ++ class OpenedFileTest(tests.support.TestCase): def test_presumed_name(self): --- -2.41.0 + ofile = needs_restarting.OpenedFile(