From f5a01b194c72680d52f04c199e289dec6c221feb Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Wed, 22 Sep 2004 22:42:05 +0000 Subject: [PATCH] Make the patch safer by using strlcpy() instead of strncpy(), and by checking to see if the unlink() call failed to remove an existing file. --- mkfifo.diff | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mkfifo.diff b/mkfifo.diff index 2703d7d..21562d2 100644 --- a/mkfifo.diff +++ b/mkfifo.diff @@ -12,8 +12,8 @@ #include #endif --- orig/syscall.c 2004-08-02 21:56:59 -+++ syscall.c 2004-06-18 17:38:35 -@@ -76,6 +76,29 @@ int do_mknod(char *pathname, mode_t mode ++++ syscall.c 2004-09-22 22:34:50 +@@ -76,6 +76,28 @@ int do_mknod(char *pathname, mode_t mode { if (dry_run) return 0; RETURN_ERROR_IF_RO_OR_LO; @@ -28,13 +28,12 @@ + int len = strlen(pathname) + 1; /* include null */ + + saddr.sun_family = AF_UNIX; -+ strncpy(saddr.sun_path, pathname, sizeof saddr.sun_path); ++ strlcpy(saddr.sun_path, pathname, sizeof saddr.sun_path); + saddr.sun_len = len > sizeof saddr.sun_path ? sizeof saddr.sun_path : len; + -+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) -+ return -1; -+ unlink(pathname); -+ if ((bind(sock, (struct sockaddr*)&saddr, sizeof saddr)) < 0) ++ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ++ || (unlink(pathname) < 0 && errno != ENOENT) ++ || (bind(sock, (struct sockaddr*)&saddr, sizeof saddr)) < 0) + return -1; + close(sock); + return do_chmod(pathname, mode); -- 2.34.1