From: Theodore Ts'o Date: Mon, 21 Jan 2008 18:43:18 +0000 (-0500) Subject: resize2fs: Add sanity check for off_t overflow before truncating X-Git-Tag: v1.40.5~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98dca6c552d73cc39a3cb9d16947b2df5c55ef21;p=thirdparty%2Fe2fsprogs.git resize2fs: Add sanity check for off_t overflow before truncating If we can't use ftruncate64(), and have to use ftruncate() instead, make sure that we don't accidentally truncate the size when we chop it down to an off_t before calling ftruncate(), lest we severely damage a filesystem image file. Signed-off-by: "Theodore Ts'o" --- diff --git a/resize/main.c b/resize/main.c index 7db4ebc35..b3f80f7e6 100644 --- a/resize/main.c +++ b/resize/main.c @@ -416,7 +416,9 @@ int main (int argc, char ** argv) #ifdef HAVE_FSTAT64 ftruncate64(fd, new_file_size); #else - ftruncate(fd, (off_t) new_file_size); + /* Only truncate if new_file_size doesn't overflow off_t */ + if (((off_t) new_file_size) == new_file_size) + ftruncate(fd, (off_t) new_file_size); #endif } if (fd > 0)