⬢ DragonFlyBSD Kernel Audit
DF-4766 / fix.diff
← back to finding ↓ download raw
--- hptproc.c.orig	2026-09-23 11:48:38.898510974 +0000
+++ hptproc.c.fixed	2026-09-23 11:49:08.182128484 +0000
@@ -372,7 +372,7 @@
 static void
 hpt_copy_disk_info(HPT_GET_INFO *pinfo, PVDevice pVDev, UINT iChan)
 {
-	char name[32], arrayname[16], *status;
+	char name[32], arrayname[MAX_ARRAY_NAME + 1], *status;
 
 	get_disk_name(name, &pVDev->u.disk);
 
@@ -386,6 +386,7 @@
 #ifdef SUPPORT_ARRAY
 	if(pVDev->pParent) {
 		memcpy(arrayname, pVDev->pParent->u.array.ArrayName, MAX_ARRAY_NAME);
+		arrayname[MAX_ARRAY_NAME] = '\0';
 		if (pVDev->pParent->u.array.CriticalMembers & (1<<pVDev->bSerialNumber))
 			status = "Degraded";
 	}
@@ -450,18 +451,26 @@
 			else
 				pTmpArray = pArray;
 
-			if (pTmpArray->u.array.rf_rebuilding) {
+			if (pTmpArray->u.array.rf_rebuilding ||
+			    pTmpArray->u.array.rf_verifying) {
+				/* DF-4765: guard the percentage divisor */
+				LBA_T denom = 0;
+				if (pTmpArray->u.array.bArnMember > 1)
+					denom = (pTmpArray->VDeviceCapacity /
+						 (pTmpArray->u.array.bArnMember - 1)) >> 11;
 #ifdef DEBUG
-				ksprintf(buf, "Rebuilding %lldMB", (pTmpArray->u.array.RebuildSectors>>11));
+				ksprintf(buf, "%s %lldMB",
+				    pTmpArray->u.array.rf_rebuilding ?
+					"Rebuilding" : "Verifying",
+				    (pTmpArray->u.array.RebuildSectors>>11));
 #else
-				ksprintf(buf, "Rebuilding %d%%", (UINT)((pTmpArray->u.array.RebuildSectors>>11)*100/((pTmpArray->VDeviceCapacity/(pTmpArray->u.array.bArnMember-1))>>11)));
+				ksprintf(buf, "%s %d%%",
+				    pTmpArray->u.array.rf_rebuilding ?
+					"Rebuilding" : "Verifying",
+				    denom ? (UINT)((pTmpArray->u.array.RebuildSectors>>11)*100/denom) : 0);
 #endif
 				sStatus = buf;
 			}
-			else if (pTmpArray->u.array.rf_verifying) {
-				ksprintf(buf, "Verifying %d%%", (UINT)((pTmpArray->u.array.RebuildSectors>>11)*100/((pTmpArray->VDeviceCapacity/(pTmpArray->u.array.bArnMember-1))>>11)));
-				sStatus = buf;
-			}
 			else if (pTmpArray->u.array.rf_need_rebuild)
 				sStatus = "Critical";
 			else if (pTmpArray->u.array.rf_broken)
@@ -532,7 +541,11 @@
 				if (pVDev->pParent)
 					/* in this case, pVDev can only be a RAID 1 source disk. */
 					if (pVDev->pParent->VDeviceType==VD_RAID_1 && pVDev==pVDev->pParent->u.array.pMember[0])
+					{
+						/* DF-4764: display the array, never the member disk */
+						pVDev = pVDev->pParent;
 						goto is_array;
+					}
 #endif
 				get_disk_name(name, &pVDev->u.disk);