]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
ext4: replace strcmp with direct comparison for '.' and '..'
authorTheodore Ts'o <tytso@mit.edu>
Sat, 12 Jul 2025 18:12:47 +0000 (14:12 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 18 Jul 2025 03:25:21 +0000 (23:25 -0400)
commit3658b8b3398eb2a49ee8d1ac88e5cdc41764f1c9
treeb8107417e3cd2952a05d7dceef2548d74043a89b
parent91b8ca8b26729b729dda8a4eddb9aceaea706f37
ext4: replace strcmp with direct comparison for '.' and '..'

In a discussion over a proposed patch, "ext4: replace strcpy() with
'.' assignment"[1], I had asserted that directory entries in ext4 were
not NUL terminated, and hence it was safe to replace strcpy() with a
direct assignment.  As it turns out, this was incorrect.  It's true
for all all directory entries *except* for '.' and '..' where the
kernel was using strcmp() and where e2fsck actually checks and offers
to fix things if '.'  and '..' are not NUL terminated.

[1] https://lore.kernel.org/r/202505191316.JJMnPobO-lkp@intel.com

We can't change this without breaking old kernel versions, but in the
spirit of "be liberal in what you receive", use direct comparison of
de->name_len and de->name[0,1] instead of strcmp().  This has the side
benefit of reducing the compiled text size by 96 bytes on x86_64.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Link: https://patch.msgid.link/20250712181249.434530-1-tytso@mit.edu
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/namei.c