Commit 3658b8b
committed
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>1 parent 91b8ca8 commit 3658b8b
1 file changed
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3082 | 3082 | | |
3083 | 3083 | | |
3084 | 3084 | | |
3085 | | - | |
| 3085 | + | |
| 3086 | + | |
3086 | 3087 | | |
3087 | 3088 | | |
3088 | 3089 | | |
| |||
3091 | 3092 | | |
3092 | 3093 | | |
3093 | 3094 | | |
3094 | | - | |
| 3095 | + | |
| 3096 | + | |
3095 | 3097 | | |
3096 | 3098 | | |
3097 | 3099 | | |
| |||
3532 | 3534 | | |
3533 | 3535 | | |
3534 | 3536 | | |
3535 | | - | |
| 3537 | + | |
3536 | 3538 | | |
3537 | 3539 | | |
3538 | 3540 | | |
| |||
3543 | 3545 | | |
3544 | 3546 | | |
3545 | 3547 | | |
3546 | | - | |
| 3548 | + | |
| 3549 | + | |
3547 | 3550 | | |
3548 | 3551 | | |
3549 | 3552 | | |
| |||
0 commit comments