Skip to contentSkip to conversation

mtg: docg3: potential divide by zero in doc_write_oob()

PATCH Applied Dan Carpenter 3 participants 3 messages Nov 29, 2012 – Dec 10, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtg: docg3: potential divide by zero in doc_write_oob()

If we set oobdelta to zero then we will either return -EINVAL or hit a divide (modulus) by zero on the next line when we check "(ooblen % oobdelta)". It's better to just return -EINVAL here instead.

---
Static analysis. I don't know if it's actually possible to hit this condition.

drivers/mtd/devices/docg3.c +1 -1
index d34d83b..8510ccb 100644
@@ -1440,7 +1440,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
 		oobdelta = mtd->ecclayout->oobavail;
 		break;
 	default:
-		oobdelta = 0;
+		return -EINVAL;
 	}
 	if ((len % DOC_LAYOUT_PAGE_SIZE) || (ooblen % oobdelta) ||
 	    (ofs % DOC_LAYOUT_PAGE_SIZE))
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

If we set oobdelta to zero then we will either return -EINVAL or hit a divide (modulus) by zero on the next line when we check "(ooblen % oobdelta)". It's better to just return -EINVAL here instead.

---
Static analysis. I don't know if it's actually possible to hit this condition.

I don't know any possibility to reach that condition, nonetheless the patch makes the code more robust, therefore :

Cheers.

--
Robert

#2 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

If we set oobdelta to zero then we will either return -EINVAL or hit a divide (modulus) by zero on the next line when we check "(ooblen % oobdelta)". It's better to just return -EINVAL here instead.

Pushed to l2-mtd.git, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy