Fixes ext2 lookup bug
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 6 Oct 2010 01:22:52 +0000 (18:22 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:55 +0000 (17:35 -0700)
You could match on example.txt with example.txtttttt, since lookup
stopped caring after the number of chars in the real file name.

kern/src/ext2fs.c

index fcc333e..11ab6a7 100644 (file)
@@ -858,9 +858,11 @@ struct dentry *ext2_lookup(struct inode *dir, struct dentry *dentry,
                        dir_i = dir_buf;
                        assert(dir_buf);
                }
-               /* Test if we're the one (TODO: use d_compare) */
+               /* Test if we're the one (TODO: use d_compare).  Note, dir_name is not
+                * null terminated, hence the && test. */
                if (!strncmp((char*)dir_i->dir_name, dentry->d_name.name,
-                            dir_i->dir_namelen)){
+                            dir_i->dir_namelen) &&
+                           (dentry->d_name.name[dir_i->dir_namelen] == '\0')) {
                        load_inode(dentry, le32_to_cpu(dir_i->dir_inode));
                        /* TODO: (HASH) add dentry to dcache (maybe the caller should) */
                        ext2_put_metablock(dir_buf);