Properly handle command line truncation

Unlikely to happen since ARG_MAX is 256K, but...
This commit is contained in:
C. McEnroe 2020-08-17 12:57:50 -04:00
parent 84b2c1858a
commit 41f9a167e3

View File

@ -212,15 +212,21 @@ void serviceStart(struct Service *service) {
); );
assert(n > 0); assert(n > 0);
len += n; len += n;
if (len >= sizeof(command)) errx(ExitNoExec, "command truncated");
} }
snprintf(&command[len], sizeof(command) - len, "exec %s", service->command); int n = snprintf(
&command[len], sizeof(command) - len, "exec %s", service->command
);
assert(n > 0);
len += n;
if (len >= sizeof(command)) errx(ExitNoExec, "command truncated");
execle( execle(
_PATH_BSHELL, _PATH_BSHELL,
_PATH_BSHELL, "-c", command, service->name, NULL, _PATH_BSHELL, "-c", command, service->name, NULL,
serviceEnviron serviceEnviron
); );
err(ExitNotFound, "%s", _PATH_BSHELL); err(ExitNoExec, "%s", _PATH_BSHELL);
} }
void serviceSignal(struct Service *service, int signal) { void serviceSignal(struct Service *service, int signal) {