From cefbe499db1a418bc41459cd04fb2965450677d8 Mon Sep 17 00:00:00 2001 From: "Guy M. Broome" Date: Mon, 5 Mar 2018 16:27:27 -0500 Subject: [PATCH] Solaris: fix malloc() / free() issues with zone name handling --- solaris/SolarisProcess.c | 6 +++--- solaris/SolarisProcess.h | 6 +++--- solaris/SolarisProcessList.c | 18 ++++++++++-------- solaris/SolarisProcessList.h | 6 +++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index b935a814..a9aff4cb 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -34,10 +34,10 @@ typedef enum SolarisProcessFields { typedef struct SolarisProcess_ { - Process super; - int kernel; + Process super; + int kernel; zoneid_t zoneid; - char zname[ZONENAME_MAX+1]; + char* zname; taskid_t taskid; projid_t projid; poolid_t poolid; diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index e1f4945a..5c98895c 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -26,10 +26,10 @@ typedef enum SolarisProcessFields { typedef struct SolarisProcess_ { - Process super; - int kernel; + Process super; + int kernel; zoneid_t zoneid; - char zname[ZONENAME_MAX+1]; + char* zname; taskid_t taskid; projid_t projid; poolid_t poolid; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 2c4d964b..d3473e20 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -7,8 +7,8 @@ in the source distribution for its full text. */ #include "ProcessList.h" -#include "SolarisProcessList.h" #include "SolarisProcess.h" +#include "SolarisProcessList.h" #include #include @@ -31,7 +31,7 @@ in the source distribution for its full text. #include #include -#include +#include #include #include #include @@ -72,15 +72,17 @@ static void setCommand(Process* process, const char* command, int len) { process->commLen = len; } -static void setZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { +char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { + char* zname; if ( sproc->zoneid == 0 ) { - strncpy( sproc->zname, "global ", 11); + zname = xStrdup("global "); } else if ( kd == NULL ) { - strncpy( sproc->zname, "unknown ", 11); + zname = xStrdup("unknown "); } else { kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); - strncpy( sproc->zname, ks->ks_name, strlen(ks->ks_name) ); + zname = xStrdup(ks->ks_name); } + return zname; } ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { @@ -325,7 +327,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->nlwp = _psinfo.pr_nlwp; proc->session = _pstatus.pr_sid; setCommand(proc,_psinfo.pr_fname,PRFNSZ); - setZoneName(spl->kd,sproc); + sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); proc->majflt = _prusage.pr_majf; proc->minflt = _prusage.pr_minf; proc->m_resident = (_psinfo.pr_rssize)/8; @@ -354,7 +356,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->nlwp = _psinfo.pr_nlwp; proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); setCommand(proc,_psinfo.pr_fname,PRFNSZ); - setZoneName(spl->kd,sproc); + sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); proc->majflt = _prusage.pr_majf; proc->minflt = _prusage.pr_minf; proc->m_resident = (_psinfo.pr_rssize)/8; diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 5690ee87..731f2941 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -15,7 +15,7 @@ in the source distribution for its full text. #include #include -#include +#include #include #include #include @@ -44,10 +44,14 @@ typedef struct SolarisProcessList_ { CPUData* cpus; } SolarisProcessList; + +char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc); + ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); void ProcessList_goThroughEntries(ProcessList* this); + #endif