From 1d4074f3ed3da1fde3b6bbbfa744ab92823886df Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 31 Dec 2019 19:00:49 -0500 Subject: [PATCH] libext2fs: chage ext2_off_t and ext2_off64_t to be signed types The ext2_off_t and ext2_off64_t types are used by ext2_file_lseek() and ext2_file_llseek(), and they need to be signed so that it can be a negative offset from the end of the file when EXT2_SEEK_END is used. Signed-off-by: Theodore Ts'o --- lib/ext2fs/blknum.c | 3 +++ lib/ext2fs/ext2fs.h | 4 ++-- lib/ext2fs/ext_attr.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c index 31055c34c..ec77a067b 100644 --- a/lib/ext2fs/blknum.c +++ b/lib/ext2fs/blknum.c @@ -537,6 +537,9 @@ void ext2fs_file_acl_block_set(ext2_filsys fs, struct ext2_inode *inode, errcode_t ext2fs_inode_size_set(ext2_filsys fs, struct ext2_inode *inode, ext2_off64_t size) { + if (size < 0) + return EINVAL; + /* Only regular files get to be larger than 4GB */ if (!LINUX_S_ISREG(inode->i_mode) && (size >> 32)) return EXT2_ET_FILE_TOO_BIG; diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index ca5e3321a..cbf0c6f4d 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -77,8 +77,8 @@ typedef __u32 __bitwise ext2_ino_t; typedef __u32 __bitwise blk_t; typedef __u64 __bitwise blk64_t; typedef __u32 __bitwise dgrp_t; -typedef __u32 __bitwise ext2_off_t; -typedef __u64 __bitwise ext2_off64_t; +typedef __s32 __bitwise ext2_off_t; +typedef __s64 __bitwise ext2_off64_t; typedef __s64 __bitwise e2_blkcnt_t; typedef __u32 __bitwise ext2_dirhash_t; diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index affc1a8fc..871319a5a 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -924,8 +924,8 @@ static errcode_t read_xattrs_from_buffer(struct ext2_xattr_handle *handle, !(ea_inode->i_flags & EXT4_EA_INODE_FL) || ea_inode->i_links_count == 0) err = EXT2_ET_EA_INODE_CORRUPTED; - else if (ext2fs_file_get_size(ea_file) != - entry->e_value_size) + else if ((__u64) ext2fs_file_get_size(ea_file) != + entry->e_value_size) err = EXT2_ET_EA_BAD_VALUE_SIZE; else err = ext2fs_file_read(ea_file, x->value, -- 2.39.2