Re: [PATCH 1/1] FS/OMFS: block number sanity check during fill_super operation

From: Fabian Frederick
Date: Thu Jun 26 2014 - 14:45:52 EST


On Thu, 26 Jun 2014 11:35:57 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Jun 26, 2014 11:28 AM, "Fabian Frederick" <fabf@xxxxxxxxx> wrote:
> >
> > Sorry but I don't see a problem with 2^31 value.
>
> It's not really 2^31.
>
> It's *negative* 2^31.
>
> 1 is "int", so it's a signed number. With the shift it ends up being a
> signed number with the high bit set. That's just a bad bad idea.
>
> Now, it just so happens that if you always compare it with unsigned
> numbers, C promotion rules will end up promoting it to unsigned and it
> happens to *work*, but that is more luck than design.
>
> So I'd suggest using 0x80000000 (which is unsigned) or use (1ul<<31) or
> similar explicit C typing.

Ok, I understand now. Thanks a lot for taking the time to explain Linus.
It really means a lot to me.

Fabian
>
> Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/