On Fri, Jan 21, 2022 at 12:17:48PM +0100, Miquel Raynal wrote: > Hi Dan, > > dan.carpenter@xxxxxxxxxx wrote on Fri, 21 Jan 2022 08:38:36 +0300: > > > The problem is that "erasesize" is a uint32_t type so it might be > > Don't you mean uint64_t here? Otherwise I don't get the sentence. > Yeah. I meant uint64_t. Will resend. > > non-zero but the truncated "(uint32_t)erasesize" value *is* zero. That > > s/*is*/*can* be/ ? (again, if my understanding is correct). > It might be a situation where "erasesize" is non-zero but after we truncated it "(uint32_t)erasesize" is zero. > > would lead to the divide by zero bug. > > > > Avoid the bug by delaying the divide until after we have validated > > that "erasesize" is reasonable. > > I don't really get the fix. If "erasesize" is big enough, then > (uint32_t)erasesize can however be zero. But checking if erasesize is > zero beforehands does not fix the situation. Or am I missing > something? It doesn't just check for zero, it checks a couple other things including if erasesize > UINT_MAX. regards, dan carpenter