From 3ac2a6f1b5e200e184a255c2cfd8ed90cb192724 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Sun, 3 Apr 2011 11:21:31 +0200 Subject: [PATCH] uml: Remove PATH_MAX sized stack allocation from /proc parsing code --- src/uml/uml_driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index e2bd5f2582..33849a07e1 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1036,21 +1036,25 @@ static char *umlGetCapabilities(virConnectPtr conn) { -static int umlGetProcessInfo(unsigned long long *cpuTime, int pid) { - char proc[PATH_MAX]; +static int umlGetProcessInfo(unsigned long long *cpuTime, int pid) +{ + char *proc; FILE *pidinfo; unsigned long long usertime, systime; - if (snprintf(proc, sizeof(proc), "/proc/%d/stat", pid) >= (int)sizeof(proc)) { + if (virAsprintf(&proc, "/proc/%d/stat", pid) < 0) { return -1; } if (!(pidinfo = fopen(proc, "r"))) { /* VM probably shut down, so fake 0 */ *cpuTime = 0; + VIR_FREE(proc); return 0; } + VIR_FREE(proc); + if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) { umlDebug("not enough arg"); VIR_FORCE_FCLOSE(pidinfo); -- 2.47.2