syslogd fails strangely when the path of a log socket exceeds
sizeof(sun_path) (defined in sys/un.h as 104) by one byte :
# logdir='syslog_________________________________________'
# testdir="/tmp/$logdir/$logdir"
# socket_path="$testdir/log"
# echo ${#socket_path} # path length, not counting the terminating NUL
104
# mkdir -p "$testdir" && syslogd -p "$socket_path"
syslogd: cannot chmod /tmp/syslog_[...SNIP...]_/syslog__________________
# ls "$testdir"
lo
syslogd binds the socket to "$testdir/lo" and then tries to change the
mode of "$testdir/log" which fails since the file does not exist.
The diff below checks for truncation as suggested in strlcpy(3).
Nicolas Bedos
Index: src/usr.sbin/syslogd/syslogd.c
===================================================================
RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.111
diff -u -p -u -r1.111 syslogd.c
--- src/usr.sbin/syslogd/syslogd.c 14 Jul 2014 04:02:33 -0000 1.111
+++ src/usr.sbin/syslogd/syslogd.c 2 Dec 2014 21:17:43 -0000
@@ -1734,7 +1734,7 @@ unix_socket(char *path, int type, mode_t
memset(&s_un, 0, sizeof(s_un));
s_un.sun_family = AF_UNIX;
- if (strlcpy(s_un.sun_path, path, sizeof(s_un.sun_path)) >
+ if (strlcpy(s_un.sun_path, path, sizeof(s_un.sun_path)) >=
sizeof(s_un.sun_path)) {
snprintf(errbuf, sizeof(errbuf), "socket path too long: %s",
path);