From bb1d98b68777f621f19530c3d17ba2b241b3c4c2 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 10 Apr 2010 12:57:17 +0000 Subject: [PATCH] * The volume init wasn't checked, so a failed init would crash. * Unlocking a removable drive was done in the wrong error label which would've resulted in accessing deadbeef due to the volume being freed just before its use or using the not initialized volume variable. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36103 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/fat/dosfs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/fat/dosfs.c b/src/add-ons/kernel/file_systems/fat/dosfs.c index b832125df1..c43de2dd30 100644 --- a/src/add-ons/kernel/file_systems/fat/dosfs.c +++ b/src/add-ons/kernel/file_systems/fat/dosfs.c @@ -577,6 +577,11 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags, } vol = volume_init(fd, buf, vol_flags, fs_flags, &geo); + if (vol == NULL) { + dprintf("dosfs error: failed to initialize volume\n"); + err = B_ERROR; + goto error1; + } /* check that the partition is large enough to contain the file system */ if (vol->total_sectors > geo.sectors_per_track * geo.cylinder_count @@ -664,12 +669,13 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags, error3: uninit_vcache(vol); error2: - volume_uninit(vol); -error1: if (!(vol->flags & B_FS_IS_READONLY) && (vol->flags & B_FS_IS_REMOVABLE) && (vol->fs_flags & FS_FLAGS_LOCK_DOOR)) { lock_removable_device(fd, false); } + + volume_uninit(vol); +error1: close(fd); error0: return err >= B_NO_ERROR ? EINVAL : err;