From: Diego Nieto Cid <[email protected]>

---
 libdiskfs/diskfs.h |  8 +++-----
 libdiskfs/lookup.c | 44 +++++++++++++++-----------------------------
 2 files changed, 18 insertions(+), 34 deletions(-)

diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 8f5db533..7f9a5777 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -775,10 +775,8 @@ diskfs_disknode_node (struct disknode *disknode)
    either be LOOKUP, CREATE, RENAME, or REMOVE.  CRED identifies the
    user making the call.
 
-   NAME will have leading and trailing slashes stripped.  It is an
-   error if there are internal slashes.  NAME will be modified in
-   place if there are slashes in it; it is therefore an error to
-   specify a constant NAME which contains slashes.
+   NAME will have slashes verified. It is an error if there are any
+   slashes and EINVAL will be returned in such cases.
 
    If the name is found, return zero, and (if NP is nonzero) set *NP
    to point to the node for it, locked.  If the name is not found,
@@ -822,7 +820,7 @@ diskfs_disknode_node (struct disknode *disknode)
    This function is a wrapper for diskfs_lookup_hard.
 */
 error_t diskfs_lookup (struct node *dp,
-                      char *name, lookup_flags_t l_flags,
+                      const char *name, lookup_flags_t l_flags,
                       struct node **np, struct dirstat *ds,
                       struct protid *cred);
 
diff --git a/libdiskfs/lookup.c b/libdiskfs/lookup.c
index 87b54c01..524f731e 100644
--- a/libdiskfs/lookup.c
+++ b/libdiskfs/lookup.c
@@ -25,10 +25,8 @@
    either be LOOKUP, CREATE, RENAME, or REMOVE.  CRED identifies the
    user making the call.
 
-   NAME will have leading and trailing slashes stripped.  It is an
-   error if there are internal slashes.  NAME will be modified in
-   place if there are slashes in it; it is therefore an error to
-   specify a constant NAME which contains slashes.
+   NAME will have slashes verified. It is an error if there are any
+   slashes and EINVAL will be returned in such cases.
 
    If the name is found, return zero, and (if NP is nonzero) set *NP
    to point to the node for it, locked.  If the name is not found,
@@ -71,11 +69,12 @@
 
    This function is a wrapper for diskfs_lookup_hard.  */
 error_t
-diskfs_lookup (struct node *dp, char *name, lookup_flags_t l_flags,
+diskfs_lookup (struct node *dp, const char *name, lookup_flags_t l_flags,
               struct node **np, struct dirstat *ds, struct protid *cred)
 {
   error_t err;
   struct node *cached;
+  const char *p;
 
   if (l_flags == REMOVE || l_flags == RENAME)
     assert_backtrace (np);
@@ -87,35 +86,22 @@ diskfs_lookup (struct node *dp, char *name, lookup_flags_t 
l_flags,
       return ENOTDIR;
     }
 
-  /* Strip leading and trailing slashes. */
-  while (*name == '/')
-    name++;
-
-  if (name[0] == '\0')
+  /* Check for slashes in provided name. */
+  p = name;
+  while (*p != '\0')
     {
-      if (ds)
-       diskfs_null_dirstat (ds);
-      return EINVAL;
+      if (*p != '/')
+        ++p;
+      else
+        break;
     }
-  else
+  if (p == name || *p == '/')
     {
-      char *p = strchr (name, '/');
-      if (p != 0)
-       {
-         *p = '\0';
-         do
-           ++p;
-         while (*p == '/');
-         if (*p != '\0')
-           {
-             if (ds)
-               diskfs_null_dirstat (ds);
-             return EINVAL;
-           }
-       }
+      if (ds)
+        diskfs_null_dirstat (ds);
+      return EINVAL;
     }
 
-
   err = fshelp_access (&dp->dn_stat, S_IEXEC, cred->user);
   if (err)
     {
-- 
2.53.0


Reply via email to