• Wolfgang Denk's avatar
    Make sure that argv[] argument pointers are not modified. · 54841ab5
    Wolfgang Denk authored
    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: default avatarWolfgang Denk <wd@denx.de>
    Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
    54841ab5
Name
Last commit
Last update
..
Makefile Loading commit data...
bedbug.c Loading commit data...
cmd_ambapp.c Loading commit data...
cmd_bdinfo.c Loading commit data...
cmd_bedbug.c Loading commit data...
cmd_bmp.c Loading commit data...
cmd_boot.c Loading commit data...
cmd_bootldr.c Loading commit data...
cmd_bootm.c Loading commit data...
cmd_cache.c Loading commit data...
cmd_console.c Loading commit data...
cmd_cplbinfo.c Loading commit data...
cmd_cramfs.c Loading commit data...
cmd_dataflash_mmc_mux.c Loading commit data...
cmd_date.c Loading commit data...
cmd_dcr.c Loading commit data...
cmd_df.c Loading commit data...
cmd_diag.c Loading commit data...
cmd_display.c Loading commit data...
cmd_dtt.c Loading commit data...
cmd_echo.c Loading commit data...
cmd_eeprom.c Loading commit data...
cmd_elf.c Loading commit data...
cmd_exit.c Loading commit data...
cmd_ext2.c Loading commit data...
cmd_fat.c Loading commit data...
cmd_fdc.c Loading commit data...
cmd_fdos.c Loading commit data...
cmd_fdt.c Loading commit data...
cmd_flash.c Loading commit data...
cmd_fpga.c Loading commit data...
cmd_help.c Loading commit data...
cmd_i2c.c Loading commit data...
cmd_ide.c Loading commit data...
cmd_immap.c Loading commit data...
cmd_irq.c Loading commit data...
cmd_itest.c Loading commit data...
cmd_jffs2.c Loading commit data...
cmd_license.c Loading commit data...
cmd_load.c Loading commit data...
cmd_log.c Loading commit data...
cmd_mac.c Loading commit data...
cmd_mem.c Loading commit data...
cmd_mfsl.c Loading commit data...
cmd_mgdisk.c Loading commit data...
cmd_mii.c Loading commit data...
cmd_misc.c Loading commit data...
cmd_mmc.c Loading commit data...
cmd_mp.c Loading commit data...
cmd_mtdparts.c Loading commit data...
cmd_nand.c Loading commit data...
cmd_net.c Loading commit data...
cmd_nvedit.c Loading commit data...
cmd_onenand.c Loading commit data...
cmd_otp.c Loading commit data...
cmd_pci.c Loading commit data...
cmd_pcmcia.c Loading commit data...
cmd_portio.c Loading commit data...
cmd_reginfo.c Loading commit data...
cmd_reiser.c Loading commit data...
cmd_sata.c Loading commit data...
cmd_scsi.c Loading commit data...
cmd_setexpr.c Loading commit data...
cmd_sf.c Loading commit data...
cmd_source.c Loading commit data...
cmd_spi.c Loading commit data...
cmd_spibootldr.c Loading commit data...
cmd_strings.c Loading commit data...
cmd_terminal.c Loading commit data...
cmd_test.c Loading commit data...
cmd_tsi148.c Loading commit data...
cmd_ubi.c Loading commit data...
cmd_ubifs.c Loading commit data...
cmd_universe.c Loading commit data...
cmd_usb.c Loading commit data...
cmd_version.c Loading commit data...
cmd_vfd.c Loading commit data...
cmd_ximg.c Loading commit data...
cmd_yaffs2.c Loading commit data...
command.c Loading commit data...
console.c Loading commit data...
ddr_spd.c Loading commit data...
dlmalloc.c Loading commit data...
dlmalloc.src Loading commit data...
env_common.c Loading commit data...
env_dataflash.c Loading commit data...
env_eeprom.c Loading commit data...
env_embedded.c Loading commit data...
env_flash.c Loading commit data...
env_mgdisk.c Loading commit data...
env_nand.c Loading commit data...
env_nowhere.c Loading commit data...
env_nvram.c Loading commit data...
env_onenand.c Loading commit data...
env_sf.c Loading commit data...
exports.c Loading commit data...
fdt_support.c Loading commit data...
flash.c Loading commit data...
hush.c Loading commit data...
hwconfig.c Loading commit data...
image.c Loading commit data...
iomux.c Loading commit data...
kallsyms.c Loading commit data...
kgdb.c Loading commit data...
kgdb_stubs.c Loading commit data...
lcd.c Loading commit data...
lynxkdi.c Loading commit data...
main.c Loading commit data...
memsize.c Loading commit data...
miiphyutil.c Loading commit data...
modem.c Loading commit data...
s_record.c Loading commit data...
serial.c Loading commit data...
stdio.c Loading commit data...
system_map.c Loading commit data...
update.c Loading commit data...
usb.c Loading commit data...
usb_kbd.c Loading commit data...
usb_storage.c Loading commit data...
xyzModem.c Loading commit data...