Handle the case where argc is 0 when rebuilding argv.

We need to pass the pathname to the policy plugin in argv[0] so we
must be sure to allocate space for it even if argc is 0.
This commit is contained in:
Todd C. Miller
2022-08-18 15:07:25 -06:00
parent 23fa22975c
commit bc5016296d

View File

@@ -553,7 +553,14 @@ intercept_check_policy_req(PolicyCheckRequest *req,
}
}
/* Rebuild argv from PolicyCheckReq so it is NULL-terminated. */
/* If argv is empty, reserve an extra slot for the command. */
if (req->n_argv == 0)
req->n_argv = 1;
/*
* Rebuild argv from PolicyCheckReq so it is NULL-terminated.
* The plugin API requires us to pass the pathname to exec in argv[0].
*/
argv = reallocarray(NULL, req->n_argv + 1, sizeof(char *));
if (argv == NULL) {
closure->errstr = N_("unable to allocate memory");