summary refs log tree commit diff
path: root/service.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-17 12:57:50 -0400
committerJune McEnroe <june@causal.agency>2020-08-17 12:57:50 -0400
commit41f9a167e34106509d34575756cad9c4292e1940 (patch)
tree094a928958e5c6841fc4d0b2c4d2b4f82e266e93 /service.c
parentFlesh out documentation and improve examples (diff)
downloadcatsit-41f9a167e34106509d34575756cad9c4292e1940.tar.gz
catsit-41f9a167e34106509d34575756cad9c4292e1940.zip
Properly handle command line truncation
Unlikely to happen since ARG_MAX is 256K, but...
Diffstat (limited to '')
-rw-r--r--service.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/service.c b/service.c
index 9a3b157..39ce60e 100644
--- a/service.c
+++ b/service.c
@@ -212,15 +212,21 @@ void serviceStart(struct Service *service) {
 		);
 		assert(n > 0);
 		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(
 		_PATH_BSHELL,
 		_PATH_BSHELL, "-c", command, service->name, NULL,
 		serviceEnviron
 	);
-	err(ExitNotFound, "%s", _PATH_BSHELL);
+	err(ExitNoExec, "%s", _PATH_BSHELL);
 }
 
 void serviceSignal(struct Service *service, int signal) {