]> git.sur5r.net Git - u-boot/commit
Make sure that argv[] argument pointers are not modified.
authorWolfgang Denk <wd@denx.de>
Mon, 28 Jun 2010 20:00:46 +0000 (22:00 +0200)
committerWolfgang Denk <wd@denx.de>
Sun, 4 Jul 2010 21:55:42 +0000 (23:55 +0200)
commit54841ab50c20d6fa6c9cc3eb826989da3a22d934
tree400f22f0a12ff0ae6c472bed6ac648befc1744a2
parentb218ccb5435e64ac2318bb8b6c9594ef1cc724cd
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>
295 files changed:
api/api.c
arch/arm/cpu/arm_cortexa8/mx51/clock.c
arch/arm/cpu/arm_cortexa8/omap3/board.c
arch/arm/lib/bootm.c
arch/arm/lib/reset.c
arch/avr32/cpu/cpu.c
arch/avr32/lib/bootm.c
arch/blackfin/cpu/bootrom-asm-offsets.c.in
arch/blackfin/cpu/reset.c
arch/blackfin/lib/boot.c
arch/blackfin/lib/cmd_cache_dump.c
arch/blackfin/lib/kgdb.c
arch/i386/cpu/cpu.c
arch/i386/lib/board.c
arch/i386/lib/bootm.c
arch/i386/lib/interrupts.c
arch/i386/lib/zimage.c
arch/m68k/cpu/mcf5227x/cpu.c
arch/m68k/cpu/mcf523x/cpu.c
arch/m68k/cpu/mcf52x2/cpu.c
arch/m68k/cpu/mcf532x/cpu.c
arch/m68k/cpu/mcf5445x/cpu.c
arch/m68k/cpu/mcf547x_8x/cpu.c
arch/m68k/lib/bootm.c
arch/microblaze/cpu/interrupts.c
arch/microblaze/lib/bootm.c
arch/mips/cpu/cpu.c
arch/mips/lib/bootm.c
arch/mips/lib/bootm_qemu_mips.c
arch/nios2/cpu/epcs.c
arch/nios2/cpu/interrupts.c
arch/nios2/cpu/sysid.c
arch/nios2/lib/bootm.c
arch/powerpc/cpu/74xx_7xx/cpu.c
arch/powerpc/cpu/74xx_7xx/interrupts.c
arch/powerpc/cpu/mpc512x/cpu.c
arch/powerpc/cpu/mpc512x/diu.c
arch/powerpc/cpu/mpc512x/iim.c
arch/powerpc/cpu/mpc512x/speed.c
arch/powerpc/cpu/mpc5xx/cpu.c
arch/powerpc/cpu/mpc5xx/interrupts.c
arch/powerpc/cpu/mpc5xxx/cpu.c
arch/powerpc/cpu/mpc5xxx/interrupts.c
arch/powerpc/cpu/mpc8220/cpu.c
arch/powerpc/cpu/mpc8220/interrupts.c
arch/powerpc/cpu/mpc824x/cpu.c
arch/powerpc/cpu/mpc8260/bedbug_603e.c
arch/powerpc/cpu/mpc8260/cpu.c
arch/powerpc/cpu/mpc8260/interrupts.c
arch/powerpc/cpu/mpc83xx/cpu.c
arch/powerpc/cpu/mpc83xx/ecc.c
arch/powerpc/cpu/mpc83xx/interrupts.c
arch/powerpc/cpu/mpc83xx/speed.c
arch/powerpc/cpu/mpc85xx/cpu.c
arch/powerpc/cpu/mpc85xx/interrupts.c
arch/powerpc/cpu/mpc85xx/mp.c
arch/powerpc/cpu/mpc86xx/cpu.c
arch/powerpc/cpu/mpc86xx/interrupts.c
arch/powerpc/cpu/mpc86xx/mp.c
arch/powerpc/cpu/mpc8xx/bedbug_860.c
arch/powerpc/cpu/mpc8xx/cpu.c
arch/powerpc/cpu/ppc4xx/44x_spd_ddr2.c
arch/powerpc/cpu/ppc4xx/bedbug_405.c
arch/powerpc/cpu/ppc4xx/cmd_chip_config.c
arch/powerpc/cpu/ppc4xx/cpu.c
arch/powerpc/cpu/ppc4xx/interrupts.c
arch/powerpc/lib/bootm.c
arch/powerpc/lib/kgdb.c
arch/sh/cpu/sh2/cpu.c
arch/sh/cpu/sh3/cpu.c
arch/sh/cpu/sh4/cpu.c
arch/sh/lib/bootm.c
arch/sparc/cpu/leon2/cpu.c
arch/sparc/cpu/leon2/interrupts.c
arch/sparc/cpu/leon3/cpu.c
arch/sparc/cpu/leon3/interrupts.c
arch/sparc/include/asm/prom.h
arch/sparc/lib/board.c
arch/sparc/lib/bootm.c
board/BuS/EB+MCF-EV123/EB+MCF-EV123.c
board/BuS/eb_cpux9k2/cpux9k2.c
board/amcc/acadia/cmd_acadia.c
board/amcc/luan/luan.c
board/amcc/makalu/cmd_pll.c
board/amcc/taihu/lcd.c
board/amcc/taihu/taihu.c
board/amcc/taihu/update.c
board/amcc/taishan/lcd.c
board/amcc/taishan/showinfo.c
board/amcc/taishan/update.c
board/amcc/yucca/cmd_yucca.c
board/amirix/ap1000/ap1000.c
board/amirix/ap1000/powerspan.c
board/barco/barco.c
board/bc3450/cmd_bc3450.c
board/bf537-stamp/cmd_bf537led.c
board/cm-bf527/gpio.c
board/cm-bf537e/flash.c
board/cm-bf537u/flash.c
board/cm5200/cmd_cm5200.c
board/cm5200/fwupdate.c
board/delta/delta.c
board/digsy_mtc/cmd_mtc.c
board/eltec/bab7xx/bab7xx.c
board/eltec/elppc/elppc.c
board/esd/apc405/apc405.c
board/esd/ar405/ar405.c
board/esd/ash405/ash405.c
board/esd/canbt/canbt.c
board/esd/cms700/cms700.c
board/esd/common/auto_update.c
board/esd/common/cmd_loadpci.c
board/esd/common/lcd.c
board/esd/common/xilinx_jtag/micro.c
board/esd/cpci2dp/cpci2dp.c
board/esd/cpci405/cpci405.c
board/esd/cpci5200/cpci5200.c
board/esd/cpci750/cpci750.c
board/esd/cpci750/sdram_init.c
board/esd/cpciiser4/cpciiser4.c
board/esd/dasa_sim/cmd_dasa_sim.c
board/esd/du405/du405.c
board/esd/du440/du440.c
board/esd/hh405/hh405.c
board/esd/ocrtc/cmd_ocrtc.c
board/esd/pci405/cmd_pci405.c
board/esd/pci405/pci405.c
board/esd/pf5200/pf5200.c
board/esd/plu405/plu405.c
board/esd/pmc405de/pmc405de.c
board/esd/pmc440/cmd_pmc440.c
board/esd/tasreg/tasreg.c
board/esd/vme8349/caddy.c
board/esd/voh405/voh405.c
board/esd/wuh405/wuh405.c
board/evb64260/zuma_pbb.c
board/freescale/common/ngpixis.c
board/freescale/common/pixis.c
board/freescale/common/sys_eeprom.c
board/freescale/m5249evb/m5249evb.c
board/freescale/mpc8610hpcd/mpc8610hpcd_diu.c
board/funkwerk/vovpn-gw/vovpn-gw.c
board/g2000/g2000.c
board/hymod/bsp.c
board/inka4x0/inkadiag.c
board/keymile/km_arm/km_arm.c
board/lwmon/lwmon.c
board/lwmon5/kbd.c
board/lwmon5/lwmon5.c
board/micronas/vct/smc_eeprom.c
board/mpl/common/common_util.c
board/mpl/mip405/cmd_mip405.c
board/mpl/pati/cmd_pati.c
board/mpl/pip405/cmd_pip405.c
board/mpl/vcma9/cmd_vcma9.c
board/netstar/crcit.c
board/netstar/eeprom.c
board/pcippc2/pcippc2.c
board/pcs440ep/pcs440ep.c
board/pdm360ng/pdm360ng.c
board/pn62/cmd_pn62.c
board/ppmc7xx/ppmc7xx.c
board/prodrive/pdnb3/pdnb3.c
board/pxa255_idp/pxa_idp.c
board/r360mpi/r360mpi.c
board/renesas/sh7785lcr/rtl8169_mac.c
board/renesas/sh7785lcr/selfcheck.c
board/renesas/sh7785lcr/sh7785lcr.c
board/sacsng/sacsng.c
board/sandburst/common/ppc440gx_i2c.c
board/sandburst/karef/karef.c
board/sandburst/metrobox/metrobox.c
board/siemens/common/fpga.c
board/siemens/pcu_e/pcu_e.c
board/spear/common/spr_misc.c
board/tcm-bf537/flash.c
board/tqc/tqm5200/cmd_stk52xx.c
board/tqc/tqm5200/cmd_tb5200.c
board/tqc/tqm8272/tqm8272.c
board/trab/cmd_trab.c
board/trab/trab.c
board/trab/trab_fkt.c
board/trizepsiv/eeprom.c
board/voiceblue/eeprom.c
board/w7o/cmd_vpd.c
board/zeus/update.c
board/zeus/zeus.c
common/cmd_ambapp.c
common/cmd_bdinfo.c
common/cmd_bedbug.c
common/cmd_bmp.c
common/cmd_boot.c
common/cmd_bootldr.c
common/cmd_bootm.c
common/cmd_cache.c
common/cmd_console.c
common/cmd_cplbinfo.c
common/cmd_cramfs.c
common/cmd_dataflash_mmc_mux.c
common/cmd_date.c
common/cmd_dcr.c
common/cmd_df.c
common/cmd_diag.c
common/cmd_display.c
common/cmd_dtt.c
common/cmd_echo.c
common/cmd_eeprom.c
common/cmd_elf.c
common/cmd_exit.c
common/cmd_ext2.c
common/cmd_fat.c
common/cmd_fdc.c
common/cmd_fdos.c
common/cmd_fdt.c
common/cmd_flash.c
common/cmd_fpga.c
common/cmd_help.c
common/cmd_i2c.c
common/cmd_ide.c
common/cmd_immap.c
common/cmd_irq.c
common/cmd_itest.c
common/cmd_jffs2.c
common/cmd_license.c
common/cmd_load.c
common/cmd_log.c
common/cmd_mac.c
common/cmd_mem.c
common/cmd_mfsl.c
common/cmd_mgdisk.c
common/cmd_mii.c
common/cmd_misc.c
common/cmd_mmc.c
common/cmd_mp.c
common/cmd_mtdparts.c
common/cmd_nand.c
common/cmd_net.c
common/cmd_nvedit.c
common/cmd_onenand.c
common/cmd_otp.c
common/cmd_pci.c
common/cmd_pcmcia.c
common/cmd_portio.c
common/cmd_reginfo.c
common/cmd_reiser.c
common/cmd_sata.c
common/cmd_scsi.c
common/cmd_setexpr.c
common/cmd_sf.c
common/cmd_source.c
common/cmd_spi.c
common/cmd_spibootldr.c
common/cmd_strings.c
common/cmd_terminal.c
common/cmd_test.c
common/cmd_tsi148.c
common/cmd_ubi.c
common/cmd_ubifs.c
common/cmd_universe.c
common/cmd_usb.c
common/cmd_version.c
common/cmd_vfd.c
common/cmd_ximg.c
common/cmd_yaffs2.c
common/command.c
common/hush.c
common/image.c
common/kgdb.c
common/lcd.c
common/main.c
doc/README.standalone
drivers/gpio/pca953x.c
drivers/misc/ds4510.c
drivers/misc/fsl_pmic.c
drivers/qe/qe.c
examples/api/demo.c
examples/standalone/82559_eeprom.c
examples/standalone/atmel_df_pow2.c
examples/standalone/eepro100_eeprom.c
examples/standalone/hello_world.c
examples/standalone/interrupt.c
examples/standalone/mem_to_mem_idma2intr.c
examples/standalone/smc91111_eeprom.c
examples/standalone/smc911x_eeprom.c
examples/standalone/stubs.c
examples/standalone/test_burst.c
examples/standalone/timer.c
include/bedbug/type.h
include/command.h
include/common.h
include/exports.h
include/image.h
include/kgdb.h
include/vxworks.h
lib/vsprintf.c