diff --git a/0001-cpu_times-GetSystemTimes-function-double-dword-conve.patch b/0001-cpu_times-GetSystemTimes-function-double-dword-conve.patch new file mode 100644 index 0000000000000000000000000000000000000000..513b93701d98f816ff9f74dec9e8a44f406f8e92 --- /dev/null +++ b/0001-cpu_times-GetSystemTimes-function-double-dword-conve.patch @@ -0,0 +1,122 @@ +From 41dadf682146fb88249a15d5997d609b4cec3635 Mon Sep 17 00:00:00 2001 +From: stswandering <294912115@qq.com> +Date: Tue, 13 Mar 2018 16:39:26 +0800 +Subject: [PATCH] =?UTF-8?q?cpu=5Ftimes()=20GetSystemTimes=20function=20dou?= + =?UTF-8?q?ble=20dword=20convert=20to=20=5F=5Fint64,t=E2=80=A6=20(#1243)?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +* cpu_times() GetSystemTimes function double dword convert to __int64,then double,instead of float. + +* use double instead of a new conversion logic. + +* Py_BuildValue change f to d + +* Py_BuildValue change f to d +--- + psutil/_psutil_windows.c | 36 ++++++++++++++++++------------------ + 1 file changed, 18 insertions(+), 18 deletions(-) + +diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c +index 81d1b4a0..f164168a 100644 +--- a/psutil/_psutil_windows.c ++++ b/psutil/_psutil_windows.c +@@ -51,8 +51,8 @@ + + #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) + #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) +-#define LO_T ((float)1e-7) +-#define HI_T (LO_T*4294967296.0) ++#define LO_T 1e-7 ++#define HI_T 429.4967296 + #define BYTESWAP_USHORT(x) ((((USHORT)(x) << 8) | ((USHORT)(x) >> 8)) & 0xffff) + #ifndef AF_INET6 + #define AF_INET6 23 +@@ -899,7 +899,6 @@ psutil_virtual_mem(PyObject *self, PyObject *args) { + memInfo.ullAvailVirtual); // avail virtual + } + +- + /* + * Retrieves system CPU timing information as a (user, system, idle) + * tuple. On a multiprocessor system, the values returned are the +@@ -907,24 +906,24 @@ psutil_virtual_mem(PyObject *self, PyObject *args) { + */ + static PyObject * + psutil_cpu_times(PyObject *self, PyObject *args) { +- float idle, kernel, user, system; ++ double idle, kernel, user, system; + FILETIME idle_time, kernel_time, user_time; + + if (!GetSystemTimes(&idle_time, &kernel_time, &user_time)) + return PyErr_SetFromWindowsErr(0); + +- idle = (float)((HI_T * idle_time.dwHighDateTime) + \ ++ idle = (double)((HI_T * idle_time.dwHighDateTime) + \ + (LO_T * idle_time.dwLowDateTime)); +- user = (float)((HI_T * user_time.dwHighDateTime) + \ ++ user = (double)((HI_T * user_time.dwHighDateTime) + \ + (LO_T * user_time.dwLowDateTime)); +- kernel = (float)((HI_T * kernel_time.dwHighDateTime) + \ ++ kernel = (double)((HI_T * kernel_time.dwHighDateTime) + \ + (LO_T * kernel_time.dwLowDateTime)); + + // Kernel time includes idle time. + // We return only busy kernel time subtracting idle time from + // kernel time. + system = (kernel - idle); +- return Py_BuildValue("(fff)", user, system, idle); ++ return Py_BuildValue("(ddd)", user, system, idle); + } + + +@@ -938,7 +937,7 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) { + NTQSI_PROC NtQuerySystemInformation; + HINSTANCE hNtDll; + +- float idle, kernel, systemt, user, interrupt, dpc; ++ double idle, kernel, systemt, user, interrupt, dpc; + NTSTATUS status; + _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL; + SYSTEM_INFO si; +@@ -992,15 +991,15 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) { + idle = user = kernel = interrupt = dpc = 0; + for (i = 0; i < si.dwNumberOfProcessors; i++) { + py_tuple = NULL; +- user = (float)((HI_T * sppi[i].UserTime.HighPart) + ++ user = (double)((HI_T * sppi[i].UserTime.HighPart) + + (LO_T * sppi[i].UserTime.LowPart)); +- idle = (float)((HI_T * sppi[i].IdleTime.HighPart) + ++ idle = (double)((HI_T * sppi[i].IdleTime.HighPart) + + (LO_T * sppi[i].IdleTime.LowPart)); +- kernel = (float)((HI_T * sppi[i].KernelTime.HighPart) + ++ kernel = (double)((HI_T * sppi[i].KernelTime.HighPart) + + (LO_T * sppi[i].KernelTime.LowPart)); +- interrupt = (float)((HI_T * sppi[i].InterruptTime.HighPart) + ++ interrupt = (double)((HI_T * sppi[i].InterruptTime.HighPart) + + (LO_T * sppi[i].InterruptTime.LowPart)); +- dpc = (float)((HI_T * sppi[i].DpcTime.HighPart) + ++ dpc = (double)((HI_T * sppi[i].DpcTime.HighPart) + + (LO_T * sppi[i].DpcTime.LowPart)); + + // kernel time includes idle time on windows +@@ -2844,10 +2843,11 @@ psutil_proc_info(PyObject *self, PyObject *args) { + + for (i = 0; i < process->NumberOfThreads; i++) + ctx_switches += process->Threads[i].ContextSwitches; +- user_time = (double)process->UserTime.HighPart * 429.4967296 + \ +- (double)process->UserTime.LowPart * 1e-7; +- kernel_time = (double)process->KernelTime.HighPart * 429.4967296 + \ +- (double)process->KernelTime.LowPart * 1e-7; ++ user_time = (double)process->UserTime.HighPart * HI_T + \ ++ (double)process->UserTime.LowPart * LO_T; ++ kernel_time = (double)process->KernelTime.HighPart * HI_T + \ ++ (double)process->KernelTime.LowPart * LO_T; ++ + // Convert the LARGE_INTEGER union to a Unix time. + // It's the best I could find by googling and borrowing code here + // and there. The time returned has a precision of 1 second. +-- +2.39.0.windows.2 + diff --git a/python-psutil.spec b/python-psutil.spec index e40fd8fd86e9c015b7a1b42469d5c3d4ac01a4e5..3af464834dee77257ce7dd971407719d22f70a02 100644 --- a/python-psutil.spec +++ b/python-psutil.spec @@ -1,6 +1,6 @@ Name: python-psutil Version: 5.4.3 -Release: 9 +Release: 10 Summary: A library for retrieving information on running processes and system utilization in Python License: BSD URL: https://github.com/giampaolo/psutil @@ -8,7 +8,7 @@ Source0: https://github.com/giampaolo/psutil/archive/release-%{version}.t Patch0001: CVE-2019-18874-1.patch Patch0002: CVE-2019-18874-2.patch - +Patch0003: 0001-cpu_times-GetSystemTimes-function-double-dword-conve.patch BuildRequires: gcc python2-devel python3-devel procps-ng python2-mock python3-mock python2-ipaddress %description @@ -70,7 +70,10 @@ done %{python3_sitearch}/psutil/ %{python3_sitearch}/*.egg-info -%changelog +%changelogi +* Tue Oct 17 2023 zhangliangpengkun - 5.4.3-10 +- cpu_times() GetSystemTimes function double dword convert to __int64,t… + * Wed Oct 20 2021 yaoxin - 5.4.3-9 - Fix CVE-2019-18874