Validate Uid+Gid fields exist in proc_cred_get

This commit is contained in:
Doug MacEachern 2007-07-20 20:29:44 +00:00
parent 585d510fb4
commit 3ff8a2666d
1 changed files with 22 additions and 8 deletions

View File

@ -826,6 +826,8 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_OK;
}
#define NO_ID_MSG "[proc_cred] /proc/%lu" PROC_PSTATUS " missing "
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_cred_t *proccred)
{
@ -836,17 +838,29 @@ int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
return status;
}
ptr = strstr(buffer, "\nUid:");
if ((ptr = strstr(buffer, "\nUid:"))) {
ptr = sigar_skip_token(ptr);
proccred->uid = sigar_strtoul(ptr);
proccred->euid = sigar_strtoul(ptr);
}
else {
sigar_log_printf(sigar, SIGAR_LOG_WARN,
NO_ID_MSG "Uid", pid);
return ENOENT;
}
ptr = strstr(ptr, "\nGid:");
if ((ptr = strstr(ptr, "\nGid:"))) {
ptr = sigar_skip_token(ptr);
proccred->gid = sigar_strtoul(ptr);
proccred->egid = sigar_strtoul(ptr);
}
else {
sigar_log_printf(sigar, SIGAR_LOG_WARN,
NO_ID_MSG "Gid", pid);
return ENOENT;
}
return SIGAR_OK;
}