From 7ad802b0928693ba9b10a382d3f2d5cd2222105e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 6 Jul 2025 12:00:02 +0200 Subject: [PATCH] Add quote support to pre/post/ready/cleanup scripts - Allow scripts to take space separated arguments with quoting - Simplify script-exists check, which already checks for leading / - Unset current script on parse error - Allow setting no timeout Signed-off-by: Joachim Wiberg --- src/service.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/service.c b/src/service.c index e3080b99..29bdb8ce 100644 --- a/src/service.c +++ b/src/service.c @@ -1386,26 +1386,36 @@ static void parse_script(svc_t *svc, char *type, char *script, int *tmo, char *b if (errstr) { errx(1, "%s: tmo %s is %s (0-3600)", svc_ident(svc, NULL, 0), script, errstr); - return; + goto err; } *tmo = (int)(sec * 1000); } else { path = script; - *tmo = svc->killdelay; + if (tmo) + *tmo = svc->killdelay; + } + + if (unquote(&path, NULL)) { + errx(1, "Syntax error, unterminated quote in %s:%s", type, path); + goto err; } found = which(path); if (!found) { - /* Not in $PATH, check if path exists and is executable */ - if (access(path, X_OK)) { - logit(LOG_WARNING, "%s:%s is missing or not executable, skipping.", - type, path); - return; - } - } else - free(found); + logit(LOG_WARNING, "%s:%s is missing or not executable, skipping.", type, path); + goto err; + } + free(found); + + if (strlen(path) >= len) { + errx(1, "Command too long in %s:%s", type, path); + goto err; + } strlcpy(buf, path, len); + return; +err: + memset(buf, 0, len); } /*