If a user crafts a carefully constructed filesystem containing a
single directory entry block with an invalid checksum and fewer than
two entries, and then runs e2fsck to fix the filesystem, fsck will
crash when it tries to "compress" the short dir and passes a negative
dirent array length to qsort. Therefore, don't allow directory
"compression" in this situation.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
/* Sort the list */
resort:
- if (fd.compress)
+ if (fd.compress && fd.num_array > 1)
qsort(fd.harray+2, fd.num_array-2, sizeof(struct hash_entry),
hash_cmp);
else
}
/* Sort non-hashed directories by inode number */
- if (fd.compress)
+ if (fd.compress && fd.num_array > 1)
qsort(fd.harray+2, fd.num_array-2,
sizeof(struct hash_entry), ino_cmp);