File gpart-0.1h-array_overflow2.diff of Package gpart

--- src/gpart.c
+++ src/gpart.c
@@ -374,7 +374,7 @@
 	dos_part_entry	*t;
 	int		ne = 0;
 
-	for (t = &p[0]; t < &p[NDOSPARTS]; t++)
+	for (t = &p[0]; t <= &p[NDOSPARTS - 1]; t++)
 		if (is_ext_parttype(t))
 			ne++;
 	return (ne);
@@ -387,7 +387,7 @@
 	dos_part_entry	*t;
 	int		nr = 0;
 
-	for (t = &p[0]; t < &p[NDOSPARTS]; t++)
+	for (t = &p[0]; t <= &p[NDOSPARTS - 1]; t++)
 		if (is_real_parttype(t))
 			nr++;
 	return (nr);
@@ -457,7 +457,7 @@
 	 * ptbl sanity checks.
 	 */
 
-	for (t = p; t < &p[NDOSPARTS]; t++)
+	for (t = p; t <= &p[NDOSPARTS - 1]; t++)
 		if (! is_sane_partentry(d,t,0))
 			return (0);
 
@@ -706,7 +706,7 @@
 	while (1)
 	{
 		ep = 0;
-		for (p = pt->t_parts; p < &pt->t_parts[NDOSPARTS + 1]; p++)
+		for (p = pt->t_parts; p <= &pt->t_parts[NDOSPARTS - 1]; p++)
 			if (is_ext_parttype(p))
 			{
 				if (ep == 0)
@@ -1430,7 +1430,7 @@
 			if (no_of_ext_partitions(gp->g_p) == 0)
 				in_ext = 0;
 			rp = 0;
-			for (p = &gp->g_p[0]; p < &gp->g_p[NDOSPARTS]; p++)
+			for (p = &gp->g_p[0]; p <= &gp->g_p[NDOSPARTS - 1]; p++)
 			{
 				if (is_real_parttype(p))
 					rp = p;
@@ -1531,7 +1531,7 @@
 				in_ext = 1; ofs = gp->g_sec;
 			}
 			rp = ep = 0;
-			for (p = &gp->g_p[0]; p < &gp->g_p[NDOSPARTS]; p++)
+			for (p = &gp->g_p[0]; p <= &gp->g_p[NDOSPARTS - 1]; p++)
 			{
 				if (is_real_parttype(p))
 					rp = p;