]> git.proxmox.com Git - grub2.git/commitdiff
reiserfs: Fix handling of first entry in the directory.
authorVladimir Serbinenko <phcoder@gmail.com>
Thu, 23 Jul 2015 23:13:27 +0000 (01:13 +0200)
committerVladimir Serbinenko <phcoder@gmail.com>
Thu, 23 Jul 2015 23:23:45 +0000 (01:23 +0200)
Fixes garbage being added to "." filename.

grub-core/fs/reiserfs.c

index b78166554b98d6bfd1110593fac40b33989cd939..39736f63c6d503441b7cf7ada36f885522fc1174 100644 (file)
@@ -783,12 +783,30 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
          struct grub_reiserfs_key entry_key;
          enum grub_fshelp_filetype entry_type;
          char *entry_name;
+         char *entry_name_end = 0;
+         char c;
          
           if (!(entry_state & GRUB_REISERFS_VISIBLE_MASK))
            continue;
 
          entry_name = (((char *) directory_headers)
                        + grub_le_to_cpu16 (directory_header->location));
+         if (entry_number == 0)
+           {
+             entry_name_end = (char *) block_header
+               + grub_le_to_cpu16 (item_headers[block_position].item_location)
+               + grub_le_to_cpu16 (item_headers[block_position].item_size);
+           }
+         else
+           {
+             entry_name_end = (((char *) directory_headers)
+                       + grub_le_to_cpu16 (directory_headers[entry_number - 1].location));
+           }
+         if (entry_name_end < entry_name || entry_name_end > (char *) block_header + block_size)
+           {
+             entry_name_end = (char *) block_header + block_size;
+           }
+
          entry_key.directory_id = directory_header->directory_id;
          entry_key.object_id = directory_header->object_id;
          entry_key.u.v2.offset_type = 0;
@@ -935,7 +953,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
              else
                {
                  /* Pseudo file ".." never has stat block.  */
-                 if (grub_strcmp (entry_name, ".."))
+                 if (entry_name_end == entry_name + 2 && grub_memcmp (entry_name, "..", 2) != 0)
                    grub_dprintf ("reiserfs",
                                  "Warning : %s has no stat block !\n",
                                  entry_name);
@@ -943,18 +961,21 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
                  goto next;
                }
            }
+
+         c = *entry_name_end;
+         *entry_name_end = 0;
          if (hook (entry_name, entry_type, entry_item, hook_data))
            {
+             *entry_name_end = c;
              grub_dprintf ("reiserfs", "Found : %s, type=%d\n",
                            entry_name, entry_type);
              ret = 1;
              goto found;
            }
+         *entry_name_end = c;
 
        next:
-         *entry_name = 0; /* Make sure next entry name (which is just
-                             before this one in disk order) stops before
-                             the current one.  */
+         ;
         }
 
       if (next_offset == 0)