From 5cdf7c149d7c5bc31a934d60c56c4c3641312542 Mon Sep 17 00:00:00 2001
From: Matt Davis <mattdavis9@gmail.com>
Date: Wed, 30 May 2007 19:45:22 -0400
Subject: This patch references Ticket #22
http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/22

While this does not fix the problem.  This does throw an exception and
gracefully exitis.  The previous exit ended in a seg fault.

This exception occurs when an ext2 block is not read properly.
And can be replicated by trying to resize a ext2 drive
(such as parted -s loop-dev resize 1 1 500M)

-Matt
---
 libparted/fs/ext2/ext2.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/libparted/fs/ext2/ext2.c b/libparted/fs/ext2/ext2.c
index 2a60215..2e047b8 100644
--- a/libparted/fs/ext2/ext2.c
+++ b/libparted/fs/ext2/ext2.c
@@ -57,6 +57,12 @@ int ext2_get_block_state(struct ext2_fs *fs, blk_t block)
 	offset = block % EXT2_SUPER_BLOCKS_PER_GROUP(fs->sb);
 
 	bh = ext2_bread(fs, EXT2_GROUP_BLOCK_BITMAP(fs->gd[group]));
+    if (!bh) {
+        ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                _("Error obtaining ext2 block information."));
+        return 0;
+    }
+
 	state = bh->data[offset>>3] & _bitmap[offset&7];
 	ext2_brelse(bh, 0);
 
-- 
1.5.1.5

