Whamcloud - gitweb
Check for potential 64-bit overflow in ext2fs_get_device_size()
authorEric Sandeen <esandeen@sandeen.net>
Mon, 2 Oct 2006 13:30:41 +0000 (09:30 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 2 Oct 2006 13:30:41 +0000 (09:30 -0400)
Check for potential overflow for filesystems contained in regular files
where the filesystem image size is returned by stat64().

Signed-off-by: Eric Sandeen <esandeen@sandeen.net>
lib/ext2fs/ChangeLog
lib/ext2fs/getsize.c

index e3a9aad..a76d96b 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-02  Eric Sandeen <esandeen@sandeen.net>
+
+       * 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  <tytso@mit.edu>
 
        * bitops.h (ext2fs_swab32): Only include ext2fs_swab32() if
index a4daa03..30a9c22 100644 (file)
@@ -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;
                        }