Make the patch safer by using strlcpy() instead of strncpy(), and by
authorWayne Davison <wayned@samba.org>
Wed, 22 Sep 2004 22:42:05 +0000 (22:42 +0000)
committerWayne Davison <wayned@samba.org>
Wed, 22 Sep 2004 22:42:05 +0000 (22:42 +0000)
checking to see if the unlink() call failed to remove an existing file.

mkfifo.diff

index 2703d7d..21562d2 100644 (file)
@@ -12,8 +12,8 @@
  #include <string.h>
  #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;
 +              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);