From d22c15a43efa348170c8425c5f6490686c6e9e43 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 18 Apr 2007 21:37:42 -0400 Subject: [PATCH] ext2fs_get_device_size(): Fix potential fd descriptor leak in an error case Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/ChangeLog | 5 +++++ lib/ext2fs/getsize.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 6ad08c7..9b21251 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 30a9c22..7f6ef71 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); -- 1.8.3.1