about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKlemens Nanni <klemens@posteo.de>2021-06-14 21:37:07 +0000
committerJune McEnroe <june@causal.agency>2021-06-15 13:20:09 -0400
commitb690bd0b83ffb6d29a1cd373635864bd1b086ac7 (patch)
treec19afee6fbe05b30681ec03dfdc0e2ec4f1e9840
parentOpenBSD: pledge final promises earlier (diff)
downloadcatgirl-b690bd0b83ffb6d29a1cd373635864bd1b086ac7.tar.gz
catgirl-b690bd0b83ffb6d29a1cd373635864bd1b086ac7.zip
OpenBSD: Simplify promise creation after seprintf() introduction
Just truncate the initial promises back to the final ones after pledging
for the first time, saving code and memory.

Assign `ptr' in all initial `seprintf()' calls for consistency while
here.
Diffstat (limited to '')
-rw-r--r--chat.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/chat.c b/chat.c
index 2a64ee0..9332ca8 100644
--- a/chat.c
+++ b/chat.c
@@ -295,10 +295,9 @@ int main(int argc, char *argv[]) {
 	if (logEnable) ptr = seprintf(ptr, end, " wpath cpath");
 	if (!self.restricted) ptr = seprintf(ptr, end, " proc exec");
 
-	char *promisesFinal = strdup(promises);
-	if (!promisesFinal) err(EX_OSERR, "strdup");
+	char *promisesInitial = ptr;
 
-	seprintf(ptr, end, " inet dns");
+	ptr = seprintf(ptr, end, " inet dns");
 	int error = pledge(promises, NULL);
 	if (error) err(EX_OSERR, "pledge");
 #endif
@@ -316,9 +315,9 @@ int main(int argc, char *argv[]) {
 	int irc = ircConnect(bind, host, port);
 
 #ifdef __OpenBSD__
-	error = pledge(promisesFinal, NULL);
+	*promisesInitial = '\0';
+	error = pledge(promises, NULL);
 	if (error) err(EX_OSERR, "pledge");
-	free(promisesFinal);
 #endif
 
 	if (pass) ircFormat("PASS :%s\r\n", pass);