Blob Blame History Raw
From bca7bb94e16acb1e88df97a5ce2c38adb76b072d Mon Sep 17 00:00:00 2001
From: Brian C. Lane <bcl@redhat.com>
Date: Tue, 21 Jun 2011 10:44:16 -0700
Subject: [PATCH 2/4] libparted: don't allow values less than 1 (#665496)

When a value < 1 is used there is the possibility that the range can
overlap sector 0. The user should use smaller units instead. 0 is a
special case and is still allowed.

* libparted/unit.c (ped_unit_parse_custom): Throw error if a value
between 0 and 1 is used.
---
 libparted/unit.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/libparted/unit.c b/libparted/unit.c
index c2921e3..232f81b 100644
--- a/libparted/unit.c
+++ b/libparted/unit.c
@@ -531,6 +531,12 @@ ped_unit_parse_custom (const char* str, const PedDevice* dev, PedUnit unit,
 				_("Invalid number."));
 		goto error_free_copy;
 	}
+        if (num > 0 && num < 1) {
+            ped_exception_throw (
+                    PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                    _("Use a smaller unit instead of a value < 1"));
+            goto error_free_copy;
+        }
 
 	unit_size = ped_unit_get_size (dev, unit);
 	radius = (ped_div_round_up (unit_size, dev->sector_size) / 2) - 1;
-- 
1.7.4.4