[U-Boot] [PATCH] Prevent malloc with size 0

Wolfgang Denk
2012-10-16T10:43:31Z

Dear Marek Vasut,

In message <201210160831.20759.marex@denx.de> you wrote:
>
> > In short, returning non-NULL from malloc(0) and expecting a CPU exception
> > when it is de-referenced is not going to fly.

We should not expect to have support for any exceptions for any kind
of illegal accesses. In general, behaviours is undetermined.

> > [1] Apparently the way do do it is to reserve the entire first 4kB page and
> > mark it as 'not-present' so any access causes a page-fault.
>
> Ok, I don't mean to reopen this can of worms again ... but what're we going to
> do about this patch?

NAK it.

It is perfectly valid on most systems to dereference a pointer to
address 0 (which in almost all cases looks the same as a NULL
pointer).

Test on ARM (some i.MX31 board):

=> md 0 20
00000000: e59ff00c e59ff018 e59ff018 e59ff018 ................
00000010: e59ff018 a0000000 e59ff014 e59ff014 ................
00000020: 00000090 1fffffd0 1fffffd4 1fffffd8 ................
00000030: 1fffffdc 1fffffe0 1fffffe4 ffffffff ................
00000040: 79706f43 68676972 63282074 30322029 Copyright (c) 20
00000050: 4d203430 726f746f 20616c6f 2e636e49 04 Motorola Inc.
00000060: 6c6c4120 67697220 20737468 65736572 All rights rese
00000070: 64657672 0000002e ffffffff ffffffff rved............

Test on PPC (some MPC5200 board):

=> md 0 10
00000000: 60000000 60000000 60000000 2c050000 `...`...`...,...
00000010: 4182001c 429f0005 7d0802a6 3d080000 A...B...}...=...
00000020: 3908ffe8 483a40c1 7fe00008 7c7f1b78 9...H:@.....|..x
00000030: 3b000000 483a2739 48003519 48003465 ;...H:'9H.5.H.4e

I object against patches that will make access to this data impossible
(or even more complicated than it is now).

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Don't tell me how hard you work. Tell me how much you get done.
-- James J. Ling