xiaoxiang781216 commented on code in PR #21029:
URL: https://github.com/apache/nuttx/pull/21029#discussion_r4387034497


##########
fs/inode/fs_inodesearch.c:
##########
@@ -339,11 +346,26 @@ static int _inode_checkpath(const char *path)
 
   /* Check each segment of the path */
 
-  while (*path != '\0' && pathlen < PATH_MAX)
+  while (*ptr != '\0' && pathlen < PATH_MAX)
     {
-      if (*path == '/')
+      if (*ptr == '/')
         {
+          if (is_simple)
+            {
+              if (ptr == path)
+                {
+                  is_simple = ptr[1] != '/';
+                }
+              else if (namelen == 0 || ptr[1] == '\0' || ptr[1] == '/' ||
+                       (namelen == 1 && name[0] == '.') ||
+                       (namelen == 2 && name[0] == '.' && name[1] == '.'))
+                {
+                  is_simple = false;
+                }
+            }
+
           namelen = 0;
+          name = ptr + 1;

Review Comment:
   why need save name



##########
fs/inode/fs_inodesearch.c:
##########
@@ -353,11 +375,28 @@ static int _inode_checkpath(const char *path)
             }
         }
 
-      path++;

Review Comment:
   why change path to ptr?



##########
fs/inode/fs_inodesearch.c:
##########
@@ -325,10 +325,17 @@ static int _inode_canonicalize(FAR char *path, FAR char 
*dst_min)
 
 /****************************************************************************
  * Name: _inode_checkpath
+ *
+ * Description:
+ *   Check path length constraints and optionally report whether the path is
+ *   already a simple absolute path that needs no canonicalization.
  ****************************************************************************/
 
-static int _inode_checkpath(const char *path)
+static int _inode_checkpath(FAR const char *path, FAR bool *simple)

Review Comment:
   let's return 1 for simple format and remove simple



##########
fs/inode/fs_inodesearch.c:
##########
@@ -353,11 +375,28 @@ static int _inode_checkpath(const char *path)
             }
         }
 
-      path++;
+      ptr++;
       pathlen++;
     }
 
-  return pathlen >= PATH_MAX ? -ENAMETOOLONG : OK;
+  if (pathlen >= PATH_MAX)
+    {
+      return -ENAMETOOLONG;
+    }
+
+  if (is_simple &&
+      ((namelen == 1 && name[0] == '.') ||

Review Comment:
   why dup the check at line 359



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to