Make the patch safer by using strlcpy() instead of strncpy(), and by
[rsync/rsync-patches.git] / mkfifo.diff
CommitLineData
5d24532c
WD
1--- orig/rsync.h 2004-09-22 08:47:31
2+++ rsync.h 2004-07-03 20:23:33
3@@ -163,6 +163,10 @@ enum msgcode {
4 #include <sys/socket.h>
5 #endif
6
7+#ifdef HAVE_SYS_UN_H
8+#include <sys/un.h>
9+#endif
10+
11 #ifdef HAVE_STRING_H
12 #include <string.h>
13 #endif
14--- orig/syscall.c 2004-08-02 21:56:59
f5a01b19
WD
15+++ syscall.c 2004-09-22 22:34:50
16@@ -76,6 +76,28 @@ int do_mknod(char *pathname, mode_t mode
5d24532c
WD
17 {
18 if (dry_run) return 0;
19 RETURN_ERROR_IF_RO_OR_LO;
20+# if HAVE_MKFIFO
21+ if (S_ISFIFO(mode))
22+ return mkfifo(pathname, mode);
23+# endif
24+# if HAVE_SYS_UN_H
25+ if (S_ISSOCK(mode)) {
26+ int sock;
27+ struct sockaddr_un saddr;
28+ int len = strlen(pathname) + 1; /* include null */
29+
30+ saddr.sun_family = AF_UNIX;
f5a01b19 31+ strlcpy(saddr.sun_path, pathname, sizeof saddr.sun_path);
5d24532c
WD
32+ saddr.sun_len = len > sizeof saddr.sun_path ? sizeof saddr.sun_path : len;
33+
f5a01b19
WD
34+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0
35+ || (unlink(pathname) < 0 && errno != ENOENT)
36+ || (bind(sock, (struct sockaddr*)&saddr, sizeof saddr)) < 0)
5d24532c
WD
37+ return -1;
38+ close(sock);
39+ return do_chmod(pathname, mode);
40+ }
41+# endif
42 return mknod(pathname, mode, dev);
43 }
44 #endif