]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Fix EINVAL error on linking to a slash-trailing path [BZ #32569]
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 19 Jan 2025 13:59:13 +0000 (14:59 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 19 Jan 2025 14:11:44 +0000 (15:11 +0100)
When the target path finishes with a slash, __file_name_split_at returns
an empty file name. We can test for this to refuse doing the link.

sysdeps/mach/hurd/bind.c
sysdeps/mach/hurd/linkat.c
sysdeps/mach/hurd/mknodat.c
sysdeps/mach/hurd/symlinkat.c

index f4cf5bd14e410eb714f5b48353088463311144aa..bb408afcf64c2a0c42ad1070db92e1ce978ef818 100644 (file)
@@ -47,8 +47,12 @@ __bind  (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
       if (dir == MACH_PORT_NULL)
        return -1;
 
-      /* Create a new, unlinked node in the target directory.  */
-      err = __dir_mkfile (dir, O_CREAT, 0666 & ~_hurd_umask, &node);
+      if (! *n)
+       /* Can't bind on the existing directory itself.  */
+       err = ENOTDIR;
+      else
+       /* Create a new, unlinked node in the target directory.  */
+       err = __dir_mkfile (dir, O_CREAT, 0666 & ~_hurd_umask, &node);
 
       if (! err)
        {
index 75b4244f5750d43cbc91c927586cdcb016fdf37c..8f8e6c36fba88582a699bc1c8d8a981f9bcdd67e 100644 (file)
@@ -48,7 +48,11 @@ __linkat_common (int fromfd, const char *from, int tofd, const char *to, int at_
   todir = __file_name_split_at (tofd, to, &toname);
   if (todir != MACH_PORT_NULL)
     {
-      err = __dir_link (todir, linknode, toname, 1);
+      if (! *toname)
+       /* Can't link to the existing directory itself.  */
+       err = ENOTDIR;
+      else
+       err = __dir_link (todir, linknode, toname, 1);
       __mach_port_deallocate (__mach_task_self (), todir);
     }
   __mach_port_deallocate (__mach_task_self (), linknode);
index 13f21917661ef08e1fb4e4d93e7b84aaf5707919..c1fe3430d0ba1d6282502bfa4a2b8d36705965e9 100644 (file)
@@ -88,8 +88,12 @@ __mknodat (int fd, const char *path, mode_t mode, dev_t dev)
   if (dir == MACH_PORT_NULL)
     return -1;
 
-  /* Create a new, unlinked node in the target directory.  */
-  errnode = err = __dir_mkfile (dir, O_WRITE, (mode & ~S_IFMT) & ~_hurd_umask, &node);
+  if (! *name)
+    /* Can't link to the existing directory itself.  */
+    errnode = err = ENOTDIR;
+  else
+    /* Create a new, unlinked node in the target directory.  */
+    errnode = err = __dir_mkfile (dir, O_WRITE, (mode & ~S_IFMT) & ~_hurd_umask, &node);
 
   if (! err && translator != NULL)
     /* Set the node's translator to make it a device.  */
index 8f72b2bea20b74e108456851937b19df046d51b5..e7dfb673df84a23b7659f5864bba927c18432e71 100644 (file)
@@ -45,8 +45,12 @@ __symlinkat (const char *from, int fd, const char *to)
   if (dir == MACH_PORT_NULL)
     return -1;
 
-  /* Create a new, unlinked node in the target directory.  */
-  err = __dir_mkfile (dir, O_WRITE, 0777 & ~_hurd_umask, &node);
+  if (! *name)
+    /* Can't link to the existing directory itself.  */
+    err = ENOTDIR;
+  else
+    /* Create a new, unlinked node in the target directory.  */
+    err = __dir_mkfile (dir, O_WRITE, 0777 & ~_hurd_umask, &node);
 
   if (! err)
     {