-
- Downloads
Make sure that argv[] argument pointers are not modified.
The hush shell dynamically allocates (and re-allocates) memory for the argument strings in the "char *argv[]" argument vector passed to commands. Any code that modifies these pointers will cause serious corruption of the malloc data structures and crash U-Boot, so make sure the compiler can check that no such modifications are being done by changing the code into "char * const argv[]". This modification is the result of debugging a strange crash caused after adding a new command, which used the following argument processing code which has been working perfectly fine in all Unix systems since version 6 - but not so in U-Boot: int main (int argc, char **argv) { while (--argc > 0 && **++argv == '-') { /* ====> */ while (*++*argv) { switch (**argv) { case 'd': debug++; break; ... default: usage (); } } } ... } The line marked "====>" will corrupt the malloc data structures and usually cause U-Boot to crash when the next command gets executed by the shell. With the modification, the compiler will prevent this with an error: increment of read-only location '*argv' N.B.: The code above can be trivially rewritten like this: while (--argc > 0 && **++argv == '-') { char *arg = *argv; while (*++arg) { switch (*arg) { ... Signed-off-by:Wolfgang Denk <wd@denx.de> Acked-by:
Mike Frysinger <vapier@gentoo.org>
Showing
- api/api.c 1 addition, 1 deletionapi/api.c
- arch/arm/cpu/arm_cortexa8/mx51/clock.c 1 addition, 1 deletionarch/arm/cpu/arm_cortexa8/mx51/clock.c
- arch/arm/cpu/arm_cortexa8/omap3/board.c 1 addition, 1 deletionarch/arm/cpu/arm_cortexa8/omap3/board.c
- arch/arm/lib/bootm.c 1 addition, 1 deletionarch/arm/lib/bootm.c
- arch/arm/lib/reset.c 1 addition, 1 deletionarch/arm/lib/reset.c
- arch/avr32/cpu/cpu.c 1 addition, 1 deletionarch/avr32/cpu/cpu.c
- arch/avr32/lib/bootm.c 1 addition, 1 deletionarch/avr32/lib/bootm.c
- arch/blackfin/cpu/bootrom-asm-offsets.c.in 1 addition, 1 deletionarch/blackfin/cpu/bootrom-asm-offsets.c.in
- arch/blackfin/cpu/reset.c 1 addition, 1 deletionarch/blackfin/cpu/reset.c
- arch/blackfin/lib/boot.c 1 addition, 1 deletionarch/blackfin/lib/boot.c
- arch/blackfin/lib/cmd_cache_dump.c 2 additions, 2 deletionsarch/blackfin/lib/cmd_cache_dump.c
- arch/blackfin/lib/kgdb.c 1 addition, 1 deletionarch/blackfin/lib/kgdb.c
- arch/i386/cpu/cpu.c 1 addition, 1 deletionarch/i386/cpu/cpu.c
- arch/i386/lib/board.c 1 addition, 1 deletionarch/i386/lib/board.c
- arch/i386/lib/bootm.c 1 addition, 1 deletionarch/i386/lib/bootm.c
- arch/i386/lib/interrupts.c 1 addition, 1 deletionarch/i386/lib/interrupts.c
- arch/i386/lib/zimage.c 1 addition, 1 deletionarch/i386/lib/zimage.c
- arch/m68k/cpu/mcf5227x/cpu.c 1 addition, 1 deletionarch/m68k/cpu/mcf5227x/cpu.c
- arch/m68k/cpu/mcf523x/cpu.c 1 addition, 1 deletionarch/m68k/cpu/mcf523x/cpu.c
- arch/m68k/cpu/mcf52x2/cpu.c 7 additions, 7 deletionsarch/m68k/cpu/mcf52x2/cpu.c
Loading
Please register or sign in to comment