Okay.+ i = 2;As Sungjong said, I think that TYPE_NAME seems right to be validated in exfat_get_dentry_set().
+ while ((ep = exfat_get_validated_dentry(es, i++, TYPE_NAME))) {
First, it is possible to correctly determine that "Immediately follow the Stream Extension directory
entry as a consecutive series"
whether the TYPE_NAME check is implemented here or exfat_get_dentry_set().
It's functionally same, so it is also right to validate in either.
Second, the current implementation does not care for NameLength field, as I replied to Sungjong.
If name is not terminated with zero, the name will be incorrect.(With or without my patch) I think
TYPE_NAME and NameLength validation should not be separated from the name extraction.
If validate TYPE_NAME in exfat_get_dentry_set(), NameLength validation and name extraction should also
be implemented there.
(Otherwise, a duplication check with exfat_get_dentry_set() and here.) I will add NameLength
validation here.
Therefore, TYPE_NAME validation here should not be omitted.
Third, getting dentry and entry-type validation should be integrated.
These no longer have to be primitive.
The integration simplifies caller error checking.
You can factor out exfat_get_dentry_cached() from exfat_get_validated_dentry() and use it here.diff --git a/fs/exfat/file.c b/fs/exfat/file.c indexTYPE_FILE and TYPE_STREAM was already validated in exfat_get_dentry_set().
6707f3eb09b5..b6b458e6f5e3 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -160,8 +160,8 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
ES_ALL_ENTRIES);
if (!es)
return -EIO;
- ep = exfat_get_dentry_cached(es, 0);
- ep2 = exfat_get_dentry_cached(es, 1);
+ ep = exfat_get_validated_dentry(es, 0, TYPE_FILE);
+ ep2 = exfat_get_validated_dentry(es, 1, TYPE_STREAM);
Isn't it unnecessary duplication check ?
No, as you say.
Although TYPE is specified, it is not good not to check the null of ep/ep2.
However, with TYPE_ALL, it becomes difficult to understand what purpose ep/ep2 is used for.
Therefore, I proposed adding ep_file/ep_stream to es, and here
ep = es->ep_file;
ep2 = es->ep_stream;
How about this?
And then, You can rename ep and ep2 to ep_file and ep_stream.
Or is it better to specify TYPE_ALL?Let me see the patches.
BTW
It's been about a month since I posted this patch.
In the meantime, I created a NameLength check and a checksum validation based on this patch.
Can you review those as well?