Hi,

Test bases on commit: 1c659d5cc6830c6f4f26660e9049582afbad3fd3 maint: avoid new warning/error with gcc-4.8.0 20130105.

Error messages:
--- exp 2013-02-05 03:06:23.819999844 +0000
+++ out 2013-02-05 03:06:23.879999844 +0000
@@ -1,10 +1,6 @@
+Error: Can't have a partition outside the disk!
Model: (file)
Disk loop-file: 4294970342s
Sector size (logical/physical): 512B/512B
-Partition Table: dvh
+Partition Table: unknown
Disk Flags:
-
-Number Start End Size Type File system Name
Flags
- 9 0s 4095s 4096s extended
- 1 4294967295s 4294968294s 1000s primary
-


This issue is caused by integer overflows in libparted/labels/dvh.c, line 416, 417:
......

416         pt->pt_nblks = PED_CPU_TO_BE32 (part->geom.length);
417         pt->pt_firstlbn = PED_CPU_TO_BE32 (part->geom.start);

......

A unsigned int was return calling PED_CPU_TO_BE32, while it's assigned to pt->pt_nblks(int type), overflow may occurs if it's a magnitude value like: 4294967295. This overflow only can be observed when run test case t4100-dvh-partition-limits.sh on BE platforms like MIPS, when the "WORDS_BIGENDIAN" macro is defined.
Attached patch is going to fix it.

the best,
thank you


>From a69f93c7c8f70032a6da0e996c8caedf94643441 Mon Sep 17 00:00:00 2001
From: Ming Liu <[email protected]>
Date: Sat, 16 Feb 2013 10:16:20 +0800
Subject: [PATCH] dvh: fix several integer overflows

Integer overflows was found in libparted/labels/dvh.c, while attemptting
assign unsigned int values to int types in some places.

Defined by unsigned int instead.

Signed-off-by: Ming Liu <[email protected]>
---
 libparted/labels/dvh.h |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libparted/labels/dvh.h b/libparted/labels/dvh.h
index 4c25c99..c2ee7af 100644
--- a/libparted/labels/dvh.h
+++ b/libparted/labels/dvh.h
@@ -112,8 +112,8 @@ struct device_parameters {
 
 struct volume_directory {
 	char	vd_name[VDNAMESIZE];	/* name */
-	int	vd_lbn;			/* logical block number */
-	int	vd_nbytes;		/* file length in bytes */
+	unsigned int	vd_lbn;		/* logical block number */
+	unsigned int	vd_nbytes;	/* file length in bytes */
 };
 
 /*
@@ -125,9 +125,9 @@ struct volume_directory {
  * NOTE: pt_firstlbn SHOULD BE CYLINDER ALIGNED
  */
 struct partition_table {		/* one per logical partition */
-	int	pt_nblks;		/* # of logical blks in partition */
-	int	pt_firstlbn;		/* first lbn of partition */
-	int	pt_type;		/* use of partition */
+	unsigned int	pt_nblks;	/* # of logical blks in partition */
+	unsigned int	pt_firstlbn;	/* first lbn of partition */
+	int		pt_type;	/* use of partition */
 };
 
 #define	PTYPE_VOLHDR	0		/* partition is volume header */
-- 
1.7.0.4

Reply via email to