Skip to contentSkip to conversation

mfd: tps6507x - fix off-by-one value range checking

PATCH In review Axel Lin 2 participants 2 messages Oct 13, 2010 – Oct 19, 2010 Multifunction devices (MFD)

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 mfd: tps6507x - fix off-by-one value range checking

We use msg[0] for device register.
If bytes == (TPS6507X_MAX_REGISTER + 1),
we got a buffer overflow when doing memcpy(&msg[1], src, bytes); Thus we must ensure bytes not greater than TPS6507X_MAX_REGISTER.

---
 drivers/mfd/tps6507x.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mfd/tps6507x.c +1 -1
index fc01976..33ba772 100644
@@ -68,7 +68,7 @@ static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
 	u8 msg[TPS6507X_MAX_REGISTER + 1];
 	int ret;
 
-	if (bytes > (TPS6507X_MAX_REGISTER + 1))
+	if (bytes > TPS6507X_MAX_REGISTER)
 		return -EINVAL;
 
 	msg[0] = reg;
Signature · 1 line
1.7.2
#1 lore raw

Hi Axel,

Quoted 4 lines · Axel Lin

We use msg[0] for device register.
If bytes == (TPS6507X_MAX_REGISTER + 1),
we got a buffer overflow when doing memcpy(&msg[1], src, bytes); Thus we must ensure bytes not greater than TPS6507X_MAX_REGISTER.

Thanks, patch applied to my for-next tree.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/