提交 3ac2a6f1 编写于 作者: M Matthias Bolte

uml: Remove PATH_MAX sized stack allocation from /proc parsing code

上级 cd708ef4
...@@ -1036,21 +1036,25 @@ static char *umlGetCapabilities(virConnectPtr conn) { ...@@ -1036,21 +1036,25 @@ static char *umlGetCapabilities(virConnectPtr conn) {
static int umlGetProcessInfo(unsigned long long *cpuTime, int pid) { static int umlGetProcessInfo(unsigned long long *cpuTime, int pid)
char proc[PATH_MAX]; {
char *proc;
FILE *pidinfo; FILE *pidinfo;
unsigned long long usertime, systime; 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; return -1;
} }
if (!(pidinfo = fopen(proc, "r"))) { if (!(pidinfo = fopen(proc, "r"))) {
/* VM probably shut down, so fake 0 */ /* VM probably shut down, so fake 0 */
*cpuTime = 0; *cpuTime = 0;
VIR_FREE(proc);
return 0; 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) { 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"); umlDebug("not enough arg");
VIR_FORCE_FCLOSE(pidinfo); VIR_FORCE_FCLOSE(pidinfo);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册