erofs-utils: lib: check readlink() length for symlinks
PATCH 1/1 erofs-utils: lib: check readlink() length for symlinks
The symlink path writes inode->i_size bytes from a malloc()'d readlink() buffer without checking how many bytes readlink() returned. If the target shortens between lstat() and readlink(), uninitialised malloc() bytes end up in the image.
Return -EIO on a short readlink().
Fixes a17497f0844a ("erofs-utils: introduce inode operations")
Signed-off-by Vansh Choudhary <[email protected]>
--- lib/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/inode.c +4 -0
@@ -1562,6 +1562,10 @@ static int erofs_mkfs_handle_nondirectory(const struct erofs_mkfs_btctx *btctx,free (symlink);return -errno; } +if (ret != inode->i_size) { +free (symlink); +return -EIO ; + } } ret =erofs_write_file_from_buffer (inode, symlink);free (symlink);
Signature · 1 line
2.43.0