⬢ DragonFlyBSD Kernel Audit
DF-3662 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/netif/wpi/if_wpi.c b/sys/dev/netif/wpi/if_wpi.c
index 1111111..2222222 100644
--- a/sys/dev/netif/wpi/if_wpi.c
+++ b/sys/dev/netif/wpi/if_wpi.c
@@ -3805,11 +3805,17 @@ wpi_get_power_index(struct wpi_softc *sc, struct wpi_power_group *group,
 	/* Retrieve TX power index into gain tables from samples. */
 	for (sample = group->samples; sample < &group->samples[3]; sample++)
 		if (pwr > sample[1].power)
 			break;
+
+	if (sample[1].power == sample[0].power) {
+		/* Degenerate (corrupt/crafted) EEPROM samples: use the
+		 * nearest sample verbatim instead of dividing by zero. */
+		idx = sample[0].index;
+	} else
 	/* Fixed-point linear interpolation using a 19-bit fractional part. */
-	idx = interpolate(pwr, sample[0].power, sample[0].index,
-	    sample[1].power, sample[1].index, 19);
+		idx = interpolate(pwr, sample[0].power, sample[0].index,
+		    sample[1].power, sample[1].index, 19);
 
 	/*-
 	 * Adjust power index based on current temperature:
 	 * - if cooler than factory-calibrated: decrease output power