ext4_dir: fix non existing entry creation issue
authorrajeshvenkataraman <rajesh_venkataraman@trimble.com>
Sun, 23 Sep 2018 14:49:30 +0000 (07:49 -0700)
committerGrzegorz Kostka <kostka.grzegorz@gmail.com>
Wed, 26 Sep 2018 20:22:36 +0000 (22:22 +0200)
Added the length of the name string a a parameter.
Using strlen() on the name string may not give the correct length
in case of paths like: /mountpoint/nonexistdir1/nonexistdir2.

include/ext4_dir_idx.h
src/ext4_dir.c
src/ext4_dir_idx.c

index 74d896baa9fa43916faee36f5211ced5d7ae9370..f1c5b26dec33c4906f69957ed3c13802814510f1 100644 (file)
@@ -91,7 +91,7 @@ int ext4_dir_dx_find_entry(struct ext4_dir_search_result *result,
  * @return Error code
  */
 int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,
-                         struct ext4_inode_ref *child, const char *name);
+                         struct ext4_inode_ref *child, const char *name, uint32_t name_len);
 
 /**@brief Add new entry to indexed directory
  * @param dir           Directory i-node
index b11d6c292df610082f5429852ea40e4bb1e2b6b9..29a51c5e86533448fe20f62a20c905d8fecbb060 100644 (file)
@@ -351,7 +351,7 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
        /* Index adding (if allowed) */
        if ((ext4_sb_feature_com(sb, EXT4_FCOM_DIR_INDEX)) &&
            (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
-               r = ext4_dir_dx_add_entry(parent, child, name);
+               r = ext4_dir_dx_add_entry(parent, child, name, name_len);
 
                /* Check if index is not corrupted */
                if (r != EXT4_ERR_BAD_DX_DIR) {
index b56e9fe0f961b777e4d7fe6a509a1e6664ebbd05..f7a64dd339f8a07a9767956116d666324c42642b 100644 (file)
@@ -1230,7 +1230,7 @@ ext4_dir_dx_split_index(struct ext4_inode_ref *ino_ref,
 }
 
 int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,
-                         struct ext4_inode_ref *child, const char *name)
+                         struct ext4_inode_ref *child, const char *name, uint32_t name_len)
 {
        int rc2 = EOK;
        int r;
@@ -1257,7 +1257,6 @@ int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,
        }
 
        /* Initialize hinfo structure (mainly compute hash) */
-       uint32_t name_len = strlen(name);
        struct ext4_hash_info hinfo;
        r = ext4_dir_hinfo_init(&hinfo, &root_blk, &fs->sb, name_len, name);
        if (r != EOK) {