summary refs log tree commit diff
path: root/local.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-11-20 13:39:25 -0500
committerJune McEnroe <june@causal.agency>2019-11-20 13:39:25 -0500
commitdb43450638ae9875619ce5c5a5e821990dd68c9f (patch)
treec4cf4986e21e5a577297ef7a36a2aac08e86d0a2 /local.c
parentFormat milliseconds as int (diff)
downloadpounce-db43450638ae9875619ce5c5a5e821990dd68c9f.tar.gz
pounce-db43450638ae9875619ce5c5a5e821990dd68c9f.zip
Use strlcpy for sun_paths
My understanding is that sun_path need not be nul-terminated, but I
didn't notice that SUN_LEN actually requires it.

> The length of UNIX-domain address, required by bind(2) and connect(2),
> can be calculated by the macro SUN_LEN() defined in <sys/un.h>.  The
> sun_path field must be terminated by a NUL character to be used with
> SUN_LEN(), but the terminating NUL is not part of the address.

Thanks to Duncan Overbruck <mail@duncano.de> for the report.
Diffstat (limited to '')
-rw-r--r--local.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/local.c b/local.c
index eccd2e6..6ef452b 100644
--- a/local.c
+++ b/local.c
@@ -131,10 +131,10 @@ size_t localUnix(int fds[], size_t cap, const char *path) {
 	if (sock < 0) err(EX_OSERR, "socket");
 
 	struct sockaddr_un addr = { .sun_family = AF_UNIX };
-	if (strlen(path) > sizeof(addr.sun_path)) {
+	size_t len = strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
+	if (len >= sizeof(addr.sun_path)) {
 		errx(EX_CONFIG, "path too long: %s", path);
 	}
-	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
 
 	int error = bind(sock, (struct sockaddr *)&addr, SUN_LEN(&addr));
 	if (error) err(EX_UNAVAILABLE, "%s", path);
pan title='2020-08-27 17:23:59 -0400'>2020-08-27contrib/palaver: Remove rc scriptJune McEnroe 2020-08-27contrib/palaver: Fix database search and creationJune McEnroe 2020-08-27contrib/palaver: Use pounce's XDG directoryJune McEnroe 2020-08-27contrib/palaver: Only allow HTTPSJune McEnroe 2020-08-25Support the pounce_env rc variableJune McEnroe 2020-08-25Remove deprecated option namesJune McEnroe 2020-08-25Document configuration and data file searchJune McEnroe 2020-08-24Use dataOpen for save fileJune McEnroe 2020-08-24Use configOpen to load localCAJune McEnroe 2020-08-24Use configPath to load client cert/privJune McEnroe 2020-08-24Use configOpen in getopt_configJune McEnroe 2020-08-24Import xdg.c from catgirlJune McEnroe 2020-08-23Replace “RAND_bytes” by “getentropy”Issam E. Maghni 2020-08-16contrib/palaver: Add no message preview flagsJune McEnroe 2020-08-13contrib/palaver: Don't set channel for PMsJune McEnroe 2020-08-13Fix unintended interception of NICK after registrationJune McEnroe 2020-08-12Add Additional Components section to READMEJune McEnroe 2020-08-12Document -L / palaver optionJune McEnroe 2020-08-11contrib/palaver: Document service configurationJune McEnroe 2020-08-11contrib/palaver: Add install target and rc scriptJune McEnroe 2020-08-11contrib/palaver: Implement command and notificationsJune McEnroe