You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/17 13:32:10 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 opened a new pull request #4171: fs/tmpfs: Handle the tail '/' correctly

xiaoxiang781216 opened a new pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171


   ## Summary
   
   ## Impact
   Handle the tail '/' robustly
   
   ## Testing
   
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#issuecomment-882058101


   @xiaoxiang781216 what you think of this modification:
   ```
   +++ b/fs/tmpfs/fs_tmpfs.c
   @@ -463,6 +463,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
        {
          /* Ignore the tail '/' */
    
   +      name[len - 1] = '\0';
   +
          if (--len == 0)
            {
              return -EINVAL;
   @@ -473,8 +475,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
    
      for (i = 0;
           i < tdo->tdo_nentries &&
   -       (strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0 ||
   -       tdo->tdo_entry[i].tde_name[len] != 0);
   +       (tdo->tdo_entry[i].tde_name[len] != 0 ||
   +        strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0);
           i++);
    
      /* Return what we found, if anything */
   ```
   It will save processing time, because most of time the strncmp will not be executed.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#issuecomment-882079056


   but, the length of tde_name may shorter than len and then the access may out of bound. 


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis merged pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis merged pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171


   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis edited a comment on pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis edited a comment on pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#issuecomment-882058101


   @xiaoxiang781216 what do you think of this modification:
   ```
   +++ b/fs/tmpfs/fs_tmpfs.c
   @@ -463,6 +463,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
        {
          /* Ignore the tail '/' */
    
   +      name[len - 1] = '\0';
   +
          if (--len == 0)
            {
              return -EINVAL;
   @@ -473,8 +475,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
    
      for (i = 0;
           i < tdo->tdo_nentries &&
   -       (strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0 ||
   -       tdo->tdo_entry[i].tde_name[len] != 0);
   +       (tdo->tdo_entry[i].tde_name[len] != 0 ||
   +        strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0);
           i++);
    
      /* Return what we found, if anything */
   ```
   It will save processing time, because most of time the strncmp will not be executed.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#issuecomment-882106891


   That is true, it only should be executed if s1 > s2. Unfortunately we don't have a tde_name_len :-)


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#discussion_r671831318



##########
File path: fs/tmpfs/fs_tmpfs.c
##########
@@ -992,14 +1026,21 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs,
                            FAR struct tmpfs_directory_s **parent)
 {
   FAR struct tmpfs_object_s *to;
+  size_t len;
   int ret;
 
+  len = strlen(relpath);
+  if (len && relpath[len - 1] == '/')

Review comment:
       Done.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#discussion_r671755255



##########
File path: fs/tmpfs/fs_tmpfs.c
##########
@@ -455,6 +455,13 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
 {
   int i;
 
+  if (len && name[len - 1] == '/')

Review comment:
       Why don't you do the same as you did for namelen:
   if (len == 0)
     {
       return -EINVAL;
     }
   else if (name[len - 1] == '/')

##########
File path: fs/tmpfs/fs_tmpfs.c
##########
@@ -992,14 +1026,21 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs,
                            FAR struct tmpfs_directory_s **parent)
 {
   FAR struct tmpfs_object_s *to;
+  size_t len;
   int ret;
 
+  len = strlen(relpath);
+  if (len && relpath[len - 1] == '/')

Review comment:
       Ditto




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#discussion_r671775441



##########
File path: fs/tmpfs/fs_tmpfs.c
##########
@@ -455,6 +455,13 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
 {
   int i;
 
+  if (len && name[len - 1] == '/')

Review comment:
       Done.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis edited a comment on pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis edited a comment on pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#issuecomment-882058101


   @xiaoxiang781216 what do you think of this modification:
   ```
   --- a/fs/tmpfs/fs_tmpfs.c
   +++ b/fs/tmpfs/fs_tmpfs.c
   @@ -473,8 +473,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
    
      for (i = 0;
           i < tdo->tdo_nentries &&
   -       (strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0 ||
   -       tdo->tdo_entry[i].tde_name[len] != 0);
   +       (tdo->tdo_entry[i].tde_name[len] != 0 ||
   +        strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0);
           i++);
    
      /* Return what we found, if anything */
   ```
   It will save processing time, because most of time the strncmp will not be executed.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#discussion_r671775573



##########
File path: fs/tmpfs/fs_tmpfs.c
##########
@@ -992,14 +1026,21 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs,
                            FAR struct tmpfs_directory_s **parent)
 {
   FAR struct tmpfs_object_s *to;
+  size_t len;
   int ret;
 
+  len = strlen(relpath);
+  if (len && relpath[len - 1] == '/')

Review comment:
       We need return fail here because it's invalid that file name contain the tail '/'.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #4171: fs/tmpfs: Handle the tail '/' correctly

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#discussion_r671830622



##########
File path: fs/tmpfs/fs_tmpfs.c
##########
@@ -992,14 +1026,21 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs,
                            FAR struct tmpfs_directory_s **parent)
 {
   FAR struct tmpfs_object_s *to;
+  size_t len;
   int ret;
 
+  len = strlen(relpath);
+  if (len && relpath[len - 1] == '/')

Review comment:
       I mean: my point was the same:
   if (len == 0)
    {
     return -EINVAL;
    }
   else (relpath[len - 1] == '/') ...




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org