libprocessgroup: Add argument checks in KillProcessGroup()

Apparently there is Java code that calls KillProcessGroup() with an
invalid initialPid argument. Hence this CL that makes KillProcessGroup()
fail early if one of its arguments is invalid.

Change-Id: I42f98eed139d9d0950428d04180e4613ba74b4e6
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Bart Van Assche 2023-03-07 14:40:25 -08:00
parent dc8a0b820e
commit 51e58aced4
1 changed files with 8 additions and 0 deletions

View File

@ -446,6 +446,14 @@ static int DoKillProcessGroupOnce(const char* cgroup, uid_t uid, int initialPid,
static int KillProcessGroup(uid_t uid, int initialPid, int signal, int retries,
int* max_processes) {
if (uid < 0) {
LOG(ERROR) << __func__ << ": invalid UID " << uid;
return -1;
}
if (initialPid <= 0) {
LOG(ERROR) << __func__ << ": invalid PID " << initialPid;
return -1;
}
std::string hierarchy_root_path;
if (CgroupsAvailable()) {
CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &hierarchy_root_path);