diff --git a/Add-exception-handling-when-reading-files.patch b/Add-exception-handling-when-reading-files.patch new file mode 100644 index 0000000000000000000000000000000000000000..8e83c954b662a04cc36494252c0a45157bdaf94e --- /dev/null +++ b/Add-exception-handling-when-reading-files.patch @@ -0,0 +1,115 @@ +From b7ab85d675417db3bc2eda499ee1844f8116d51e Mon Sep 17 00:00:00 2001 +From: lingjuer +Date: Fri, 28 Jul 2023 15:40:17 +0800 +Subject: [PATCH] Add exception handling when reading files + +--- + dnf/cli/utils.py | 92 +++++++++++++++++++++++++----------------------- + 1 file changed, 47 insertions(+), 45 deletions(-) + +diff --git a/dnf/cli/utils.py b/dnf/cli/utils.py +index 1c3db75..2d3e352 100644 +--- a/dnf/cli/utils.py ++++ b/dnf/cli/utils.py +@@ -59,51 +59,53 @@ def seconds_to_ui_time(seconds): + + def get_process_info(pid): + """Return info dict about a process.""" +- +- pid = int(pid) +- +- # Maybe true if /proc isn't mounted, or not Linux ... or something. +- if (not os.path.exists("/proc/%d/status" % pid) or +- not os.path.exists("/proc/stat") or +- not os.path.exists("/proc/%d/stat" % pid)): +- return +- +- ps = {} +- with open("/proc/%d/status" % pid) as status_file: +- for line in status_file: +- if line[-1] != '\n': +- continue +- data = line[:-1].split(':\t', 1) +- if len(data) < 2: +- continue +- data[1] = dnf.util.rtrim(data[1], ' kB') +- ps[data[0].strip().lower()] = data[1].strip() +- if 'vmrss' not in ps: +- return +- if 'vmsize' not in ps: +- return +- +- boot_time = None +- with open("/proc/stat") as stat_file: +- for line in stat_file: +- if line.startswith("btime "): +- boot_time = int(line[len("btime "):-1]) +- break +- if boot_time is None: +- return +- +- with open('/proc/%d/stat' % pid) as stat_file: +- ps_stat = stat_file.read().split() +- ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21]) +- ps['state'] = {'R' : _('Running'), +- 'S' : _('Sleeping'), +- 'D' : _('Uninterruptible'), +- 'Z' : _('Zombie'), +- 'T' : _('Traced/Stopped') +- }.get(ps_stat[2], _('Unknown')) +- +- return ps +- ++ try: ++ pid = int(pid) ++ ++ # Maybe true if /proc isn't mounted, or not Linux ... or something. ++ if (not os.path.exists("/proc/%d/status" % pid) or ++ not os.path.exists("/proc/stat") or ++ not os.path.exists("/proc/%d/stat" % pid)): ++ return ++ ++ ps = {} ++ with open("/proc/%d/status" % pid) as status_file: ++ for line in status_file: ++ if line[-1] != '\n': ++ continue ++ data = line[:-1].split(':\t', 1) ++ if len(data) < 2: ++ continue ++ data[1] = dnf.util.rtrim(data[1], ' kB') ++ ps[data[0].strip().lower()] = data[1].strip() ++ if 'vmrss' not in ps: ++ return ++ if 'vmsize' not in ps: ++ return ++ ++ boot_time = None ++ with open("/proc/stat") as stat_file: ++ for line in stat_file: ++ if line.startswith("btime "): ++ boot_time = int(line[len("btime "):-1]) ++ break ++ if boot_time is None: ++ return ++ ++ with open('/proc/%d/stat' % pid) as stat_file: ++ ps_stat = stat_file.read().split() ++ ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21]) ++ ps['state'] = {'R' : _('Running'), ++ 'S' : _('Sleeping'), ++ 'D' : _('Uninterruptible'), ++ 'Z' : _('Zombie'), ++ 'T' : _('Traced/Stopped') ++ }.get(ps_stat[2], _('Unknown')) ++ ++ return ps ++ except (OSError, ValueError) as e: ++ logger.error("Failed to get process info: %s", e) ++ return None + + def show_lock_owner(pid): + """Output information about process holding a lock.""" +-- +2.39.1 + diff --git a/dnf.spec b/dnf.spec index 95a246a3726a3e32eac94140cb42df2ec058642e..17d06cb8f1e10ec1c4559f0491f5590718679b2c 100644 --- a/dnf.spec +++ b/dnf.spec @@ -3,7 +3,7 @@ Name: dnf Version: 4.14.0 -Release: 15 +Release: 16 Summary: A software package manager that manages packages on Linux distributions. License: GPLv2+ and GPLv2 and GPL URL: https://github.com/rpm-software-management/dnf @@ -28,7 +28,7 @@ Patch6004: backport-add-support-for-rollback-of-group-upgrade-rollbac Patch6005: backport-ignore-processing-variable-files-with-unsupported-encoding.patch Patch6006: backport-fix-AttributeError-when-IO-busy-and-press-ctrl-c.patch Patch6007: backport-cli-allow-=in-setopt-values.patch - +Patch6008: Add-exception-handling-when-reading-files.patch BuildArch: noarch BuildRequires: cmake gettext systemd bash-completion python3-sphinx Requires: python3-%{name} = %{version}-%{release} libreport-filesystem @@ -252,6 +252,12 @@ popd %{_mandir}/man8/%{name}-automatic.8* %changelog +* Fri Jul 28 2023 zhangchenglin - 4.14.0-116 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:Add exception handling when reading files + * Fri Jul 14 2023 chenhaixing - 4.14.0-15 - Type:bugfix - CVE:NA