From bc5016296d19e399984691c2a7fbb48ee87fc97c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 18 Aug 2022 15:07:25 -0600 Subject: [PATCH] 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. --- src/exec_intercept.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/exec_intercept.c b/src/exec_intercept.c index b99863808..8586dba12 100644 --- a/src/exec_intercept.c +++ b/src/exec_intercept.c @@ -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");