From 9690994bc3196f430e2d33522796bfd00440177b Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 14 Aug 2023 09:27:45 -0500 Subject: [PATCH] Fix issue with invalid utf-8 chars in needs-restarting Signed-off-by: Jonathan Wright --- .../0030-Fix-issue-with-invalid-utf8.patch | 71 +++++++++++++++++++ SPECS/dnf-plugins-core.spec | 6 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 SOURCES/0030-Fix-issue-with-invalid-utf8.patch diff --git a/SOURCES/0030-Fix-issue-with-invalid-utf8.patch b/SOURCES/0030-Fix-issue-with-invalid-utf8.patch new file mode 100644 index 0000000..5232387 --- /dev/null +++ b/SOURCES/0030-Fix-issue-with-invalid-utf8.patch @@ -0,0 +1,71 @@ +From 50ffed7d4750b9fe9d5dcf5b2fd77fefd636cb97 Mon Sep 17 00:00:00 2001 +From: Andy Baugh +Date: Tue, 6 Jun 2023 16:37:42 +0000 +Subject: [PATCH] Fix for strange issue with binary garbage in smaps files + += changelog = +msg: Avoid issue with garbage smaps chars in needs-restarting.py +type: bugfix +resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2212953 +related: None +--- + plugins/needs_restarting.py | 2 +- + tests/test_needs_restarting.py | 14 +++++++++++++- + 2 files changed, 14 insertions(+), 2 deletions(-) + +diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py +index a3a5f12d..0c7f8a2f 100644 +--- a/plugins/needs_restarting.py ++++ b/plugins/needs_restarting.py +@@ -74,7 +74,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 7b629b47..d7dd6d5a 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, +@@ -15,7 +16,6 @@ + # Red Hat, Inc. + # + +- + from __future__ import absolute_import + from __future__ import print_function + from __future__ import unicode_literals +@@ -24,6 +24,7 @@ + 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 +59,17 @@ def test_get_service_dbus_nounitforpid(self): + 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�Evil-13.37.so') ++ ++ + class OpenedFileTest(tests.support.TestCase): + def test_presumed_name(self): + ofile = needs_restarting.OpenedFile( diff --git a/SPECS/dnf-plugins-core.spec b/SPECS/dnf-plugins-core.spec index 0a5682d..fa840de 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: 19%{?dist} +Release: 20%{?dist}.1.alma Summary: Core Plugins for DNF License: GPLv2+ URL: https://github.com/rpm-software-management/dnf-plugins-core @@ -68,6 +68,7 @@ Patch26: 0026-Add-a-warning-when-using-system-upgrade-on-RHEL.patch Patch27: 0027-offline-upgrade-Add-security-filters.patch Patch28: 0028-system-upgrade-Show-warning-always-for-a-downstream.patch Patch29: 0029-Update-translations.patch +Patch30: 0030-Fix-issue-with-invalid-utf8.patch BuildArch: noarch @@ -844,6 +845,9 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/ %endif %changelog +* Mon Aug 14 2023 Jonathan Wright - 4.0.21-20 +- Fix issue with invalid utf-8 chars in needs-restarting rhbz#2212953 + * Wed Mar 08 2023 Marek Blaha - 4.0.21-19 - Update translations