On Mon, Jun 12, 2023 at 10:25:26AM +0200, Michal Prívozník wrote:
On 6/12/23 09:55, Martin Kletzander wrote:It is used to fill an unsigned long long anyway and if it is negative than there is really an issue somewhere. Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 2 +- src/util/virprocess.c | 17 ++++++++++------- src/util/virprocess.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 56f4cd619715..857fbfb7992c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9937,7 +9937,7 @@ qemuDomainMemoryStatsInternal(virDomainObj *vm, { int ret = -1; - long rss; + unsigned long long rss; if (virDomainObjCheckActive(vm) < 0) return -1; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index d12fe4f7171f..a9f249413ce1 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -23,6 +23,7 @@ #include <config.h> #include <fcntl.h> +#include <limits.h> #include <signal.h> #ifndef WIN32 # include <sys/wait.h> @@ -1739,7 +1740,7 @@ virProcessGetStatInfo(unsigned long long *cpuTime, unsigned long long *userTime, unsigned long long *sysTime, int *lastCpu, - long *vm_rss, + unsigned long long *vm_rss, pid_t pid, pid_t tid) { @@ -1748,14 +1749,16 @@ virProcessGetStatInfo(unsigned long long *cpuTime, unsigned long long stime = 0; const unsigned long long jiff2nsec = 1000ull * 1000ull * 1000ull / (unsigned long long) sysconf(_SC_CLK_TCK); - long rss = 0; + long pagesize = virGetSystemPageSizeKB();const please. We don't really want anybody change this value.
Of course, if someone changed the page size the machine would clearly crash =D But in all seriousness, I'll change that, but don't really see the point, especially in C.
+ unsigned long long rss = 0; int cpu = 0; if (!proc_stat || virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &utime) < 0 || virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &stime) < 0 || - virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < 0 || - virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &cpu) < 0) { + virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < 0 || + virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &cpu) < 0 || + rss > ULLONG_MAX / pagesize) { VIR_WARN("cannot parse process status data"); }Michal
Attachment:
signature.asc
Description: PGP signature