From: Eric Sandeen Date: Mon, 2 Oct 2006 13:30:41 +0000 (-0400) Subject: Check for potential 64-bit overflow in ext2fs_get_device_size() X-Git-Tag: E2FSPROGS-1_40-WIP-1114~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3efc3a04fc77bf53d5d1ad433144b82b441e0806;p=thirdparty%2Fe2fsprogs.git Check for potential 64-bit overflow in ext2fs_get_device_size() Check for potential overflow for filesystems contained in regular files where the filesystem image size is returned by stat64(). Signed-off-by: Eric Sandeen --- diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index e3a9aad55..a76d96b70 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,9 @@ +2006-10-02 Eric Sandeen + + * getsize.c (ext2fs_get_device_size): Check to make sure that the + number of blocks doesn't overflow the retblocks return + parameter for regular files using stat64(). + 2006-10-01 Theodore Tso * bitops.h (ext2fs_swab32): Only include ext2fs_swab32() if diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index a4daa03d9..30a9c224f 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -251,6 +251,11 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, if (fstat(fd, &st) == 0) #endif if (S_ISREG(st.st_mode)) { + if ((sizeof(*retblocks) < sizeof(unsigned long long)) && + ((st.st_size / blocksize) > 0xFFFFFFFF)) { + rc = EFBIG; + goto out; + } *retblocks = st.st_size / blocksize; goto out; }