From 0f71db9d8229bd53daa1fbc922ff408bfd44325f Mon Sep 17 00:00:00 2001 From: "Guy M. Broome" Date: Mon, 5 Mar 2018 16:46:52 -0500 Subject: [PATCH] Solaris: fix memory allocation for usernames (some empty usernames in 32-bit builds) --- solaris/SolarisProcessList.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index d3473e20..66a25a30 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -62,16 +62,6 @@ typedef struct SolarisProcessList_ { }*/ -static void setCommand(Process* process, const char* command, int len) { - if (process->comm && process->commLen >= len) { - strncpy(process->comm, command, len + 1); - } else { - free(process->comm); - process->comm = xStrdup(command); - } - process->commLen = len; -} - char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* zname; if ( sproc->zoneid == 0 ) { @@ -326,7 +316,8 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); proc->nlwp = _psinfo.pr_nlwp; proc->session = _pstatus.pr_sid; - setCommand(proc,_psinfo.pr_fname,PRFNSZ); + proc->comm = xStrdup(_psinfo.pr_fname); + proc->commLen = strnlen(_psinfo.pr_fname,PRFNSZ); sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); proc->majflt = _prusage.pr_majf; proc->minflt = _prusage.pr_minf; @@ -355,7 +346,8 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->pgrp = _psinfo.pr_pgid; proc->nlwp = _psinfo.pr_nlwp; proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); - setCommand(proc,_psinfo.pr_fname,PRFNSZ); + proc->comm = xStrdup(_psinfo.pr_fname); + proc->commLen = strnlen(_psinfo.pr_fname,PRFNSZ); sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); proc->majflt = _prusage.pr_majf; proc->minflt = _prusage.pr_minf;