From: Theodore Ts'o Date: Thu, 19 Apr 2007 01:37:42 +0000 (-0400) Subject: ext2fs_get_device_size(): Fix potential fd descriptor leak in an error case X-Git-Tag: E2FSPROGS-1_40~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d22c15a43efa348170c8425c5f6490686c6e9e43;p=thirdparty%2Fe2fsprogs.git ext2fs_get_device_size(): Fix potential fd descriptor leak in an error case Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 6ad08c7d0..9b2125199 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,8 @@ +2007-04-18 Theodore Tso + + * getsize.c (ext2fs_get_device_size): Make sure we don't leak a + file descriptor in some error cases. + 2007-04-14 Theodore Tso * swapfs.c (ext2fs_swap_inode_full): Fix a problem byte-swapping diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index 30a9c224f..7f6ef71b0 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -170,8 +170,10 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, #ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */ if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) { if ((sizeof(*retblocks) < sizeof(unsigned long long)) - && ((size64 / (blocksize / 512)) > 0xFFFFFFFF)) - return EFBIG; + && ((size64 / (blocksize / 512)) > 0xFFFFFFFF)) { + rc = EFBIG; + goto out; + } *retblocks = size64 / (blocksize / 512); goto out; } @@ -281,8 +283,10 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, valid_offset (fd, 0); size64 = low + 1; if ((sizeof(*retblocks) < sizeof(unsigned long long)) - && ((size64 / blocksize) > 0xFFFFFFFF)) - return EFBIG; + && ((size64 / blocksize) > 0xFFFFFFFF)) { + rc = EFBIG; + goto out; + } *retblocks = size64 / blocksize; out: close(fd);