summaryrefslogtreecommitdiff
path: root/fs/udf
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2022-10-05 19:28:33 +0300
committerJan Kara <jack@suse.cz>2023-01-09 12:39:51 +0300
commit1c80afa04db39c98aebea9aabfafa37a208cdfee (patch)
tree352ca58404ace54f62a8139c43f9f4e536114ae4 /fs/udf
parenta27b2923de7efaa1da1e243fb80ff0fa432e4be0 (diff)
downloadlinux-1c80afa04db39c98aebea9aabfafa37a208cdfee.tar.xz
udf: Implement searching for directory entry using new iteration code
Implement searching for directory entry - udf_fiiter_find_entry() - using new directory iteration code. Reported-by: syzbot+69c9fdccc6dd08961d34@syzkaller.appspotmail.com Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/udf')
-rw-r--r--fs/udf/namei.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 78bc4bbb7c54..145883d15c0f 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -141,6 +141,73 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
}
/**
+ * udf_fiiter_find_entry - find entry in given directory.
+ *
+ * @dir: directory inode to search in
+ * @child: qstr of the name
+ * @iter: iter to use for searching
+ *
+ * This function searches in the directory @dir for a file name @child. When
+ * found, @iter points to the position in the directory with given entry.
+ *
+ * Returns 0 on success, < 0 on error (including -ENOENT).
+ */
+static int udf_fiiter_find_entry(struct inode *dir, const struct qstr *child,
+ struct udf_fileident_iter *iter)
+{
+ int flen;
+ unsigned char *fname = NULL;
+ struct super_block *sb = dir->i_sb;
+ int isdotdot = child->len == 2 &&
+ child->name[0] == '.' && child->name[1] == '.';
+ int ret;
+
+ fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
+ if (!fname)
+ return -ENOMEM;
+
+ for (ret = udf_fiiter_init(iter, dir, 0);
+ !ret && iter->pos < dir->i_size;
+ ret = udf_fiiter_advance(iter)) {
+ if (iter->fi.fileCharacteristics & FID_FILE_CHAR_DELETED) {
+ if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
+ continue;
+ }
+
+ if (iter->fi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) {
+ if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
+ continue;
+ }
+
+ if ((iter->fi.fileCharacteristics & FID_FILE_CHAR_PARENT) &&
+ isdotdot)
+ goto out_ok;
+
+ if (!iter->fi.lengthFileIdent)
+ continue;
+
+ flen = udf_get_filename(sb, iter->name,
+ iter->fi.lengthFileIdent, fname, UDF_NAME_LEN);
+ if (flen < 0) {
+ ret = flen;
+ goto out_err;
+ }
+
+ if (udf_match(flen, fname, child->len, child->name))
+ goto out_ok;
+ }
+ if (!ret)
+ ret = -ENOENT;
+
+out_err:
+ udf_fiiter_release(iter);
+out_ok:
+ kfree(fname);
+
+ return ret;
+}
+
+/**
* udf_find_entry - find entry in given directory.
*
* @dir: directory inode to search in