Fiemap: validate the input arguments
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Sat, 24 Nov 2012 15:34:18 +0000 (17:34 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Sat, 24 Nov 2012 16:33:12 +0000 (18:33 +0200)
Validate the input arguments for 'get_mapped_ranges()' and
'get_unmapped_ranges()' - they should be positive and should not go beyond file
size.

Change-Id: Ib992e03c6d651bd4e00025bc1a75b69a90d95a31
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptools/Fiemap.py

index a123531..09821e0 100644 (file)
@@ -127,12 +127,20 @@ class Fiemap:
 
         return not self.block_is_mapped(block)
 
-    @staticmethod
-    def _get_ranges(start, count, test_func):
+    def _get_ranges(self, start, count, test_func):
         """ Internal helper function which implements 'get_mapped_ranges()' and
         'get_unmapped_ranges()', depending whethier 'test_func' is a
         'block_is_mapped()' or 'block_is_unmapped()' object. """
 
+        if start < 0 or count < 0:
+            raise Error("the 'start' (%d) and 'count' (%d) arguments must be " \
+                        "positive" % (start, count))
+
+        if start + count > self.blocks_cnt:
+            raise Error("file '%s' has only %d blocks, which is less than " \
+                        "the specified 'start' + 'count' = %d" \
+                        % (self._image_path, start, count))
+
         iterator = xrange(start, count)
         for key, group in itertools.groupby(iterator, test_func):
             if key: