diff options
author | Wolfgang Denk <wd@denx.de> | 2010-06-28 20:00:46 (GMT) |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2010-07-04 21:55:42 (GMT) |
commit | 54841ab50c20d6fa6c9cc3eb826989da3a22d934 (patch) | |
tree | 400f22f0a12ff0ae6c472bed6ac648befc1744a2 /examples/standalone | |
parent | b218ccb5435e64ac2318bb8b6c9594ef1cc724cd (diff) | |
download | u-boot-54841ab50c20d6fa6c9cc3eb826989da3a22d934.tar.xz |
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>
Diffstat (limited to 'examples/standalone')
-rw-r--r-- | examples/standalone/82559_eeprom.c | 2 | ||||
-rw-r--r-- | examples/standalone/atmel_df_pow2.c | 2 | ||||
-rw-r--r-- | examples/standalone/eepro100_eeprom.c | 2 | ||||
-rw-r--r-- | examples/standalone/hello_world.c | 2 | ||||
-rw-r--r-- | examples/standalone/interrupt.c | 2 | ||||
-rw-r--r-- | examples/standalone/mem_to_mem_idma2intr.c | 4 | ||||
-rw-r--r-- | examples/standalone/smc91111_eeprom.c | 2 | ||||
-rw-r--r-- | examples/standalone/smc911x_eeprom.c | 2 | ||||
-rw-r--r-- | examples/standalone/stubs.c | 2 | ||||
-rw-r--r-- | examples/standalone/test_burst.c | 2 | ||||
-rw-r--r-- | examples/standalone/timer.c | 2 |
11 files changed, 12 insertions, 12 deletions
diff --git a/examples/standalone/82559_eeprom.c b/examples/standalone/82559_eeprom.c index 5e2eee9..8dd7079 100644 --- a/examples/standalone/82559_eeprom.c +++ b/examples/standalone/82559_eeprom.c @@ -305,7 +305,7 @@ write_config_word(int bus, int dev, int func, int reg, u16 data) } -int main (int argc, char *argv[]) +int main (int argc, char * const argv[]) { unsigned char *eth_addr; uchar buf[6]; diff --git a/examples/standalone/atmel_df_pow2.c b/examples/standalone/atmel_df_pow2.c index db0cd69..b5b4503 100644 --- a/examples/standalone/atmel_df_pow2.c +++ b/examples/standalone/atmel_df_pow2.c @@ -114,7 +114,7 @@ static char *getline(void) } } -int atmel_df_pow2(int argc, char *argv[]) +int atmel_df_pow2(int argc, char * const argv[]) { /* Print the ABI version */ app_startup(argv); diff --git a/examples/standalone/eepro100_eeprom.c b/examples/standalone/eepro100_eeprom.c index 771a7e8..3c7f380 100644 --- a/examples/standalone/eepro100_eeprom.c +++ b/examples/standalone/eepro100_eeprom.c @@ -25,7 +25,7 @@ static int reset_eeprom(unsigned long ioaddr, unsigned char *hwaddr); -int eepro100_eeprom(int argc, char *argv[]) +int eepro100_eeprom(int argc, char * const argv[]) { int ret = 0; diff --git a/examples/standalone/hello_world.c b/examples/standalone/hello_world.c index 9317f6d..067c390 100644 --- a/examples/standalone/hello_world.c +++ b/examples/standalone/hello_world.c @@ -24,7 +24,7 @@ #include <common.h> #include <exports.h> -int hello_world (int argc, char *argv[]) +int hello_world (int argc, char * const argv[]) { int i; diff --git a/examples/standalone/interrupt.c b/examples/standalone/interrupt.c index f3061d1..a5b58a1 100644 --- a/examples/standalone/interrupt.c +++ b/examples/standalone/interrupt.c @@ -44,7 +44,7 @@ static void irq_handler (void *arg); -int interrupt (int argc, char *argv[]) +int interrupt (int argc, char * const argv[]) { int c, irq = -1; diff --git a/examples/standalone/mem_to_mem_idma2intr.c b/examples/standalone/mem_to_mem_idma2intr.c index f35f1ba..d0a75ea 100644 --- a/examples/standalone/mem_to_mem_idma2intr.c +++ b/examples/standalone/mem_to_mem_idma2intr.c @@ -204,9 +204,9 @@ int memcmp(const void * cs,const void * ct,size_t count) #endif /* STANDALONE */ #ifdef STANDALONE -int mem_to_mem_idma2intr (int argc, char *argv[]) +int mem_to_mem_idma2intr (int argc, char * const argv[]) #else -int do_idma (bd_t * bd, int argc, char *argv[]) +int do_idma (bd_t * bd, int argc, char * const argv[]) #endif /* STANDALONE */ { int i; diff --git a/examples/standalone/smc91111_eeprom.c b/examples/standalone/smc91111_eeprom.c index b91f34c..c98b0fc 100644 --- a/examples/standalone/smc91111_eeprom.c +++ b/examples/standalone/smc91111_eeprom.c @@ -48,7 +48,7 @@ void print_MAC (struct eth_device *dev); int read_eeprom_reg (struct eth_device *dev, int reg); void print_macaddr (struct eth_device *dev); -int smc91111_eeprom (int argc, char *argv[]) +int smc91111_eeprom (int argc, char * const argv[]) { int c, i, j, done, line, reg, value, start, what; char input[50]; diff --git a/examples/standalone/smc911x_eeprom.c b/examples/standalone/smc911x_eeprom.c index 104047f..c51a050 100644 --- a/examples/standalone/smc911x_eeprom.c +++ b/examples/standalone/smc911x_eeprom.c @@ -313,7 +313,7 @@ static char *getline(void) /** * smc911x_eeprom - our application's main() function */ -int smc911x_eeprom(int argc, char *argv[]) +int smc911x_eeprom(int argc, char * const argv[]) { /* Avoid initializing on stack as gcc likes to call memset() */ struct eth_device dev; diff --git a/examples/standalone/stubs.c b/examples/standalone/stubs.c index f3e1ab5..2d2e709 100644 --- a/examples/standalone/stubs.c +++ b/examples/standalone/stubs.c @@ -189,7 +189,7 @@ void __attribute__((unused)) dummy(void) extern unsigned long __bss_start, _end; -void app_startup(char **argv) +void app_startup(char * const *argv) { unsigned char * cp = (unsigned char *) &__bss_start; diff --git a/examples/standalone/test_burst.c b/examples/standalone/test_burst.c index 7109c09..2b101b7 100644 --- a/examples/standalone/test_burst.c +++ b/examples/standalone/test_burst.c @@ -85,7 +85,7 @@ static unsigned long test_pattern [] = { }; -int test_burst (int argc, char *argv[]) +int test_burst (int argc, char * const argv[]) { unsigned long size = CACHE_LINE_SIZE; unsigned int pass = 0; diff --git a/examples/standalone/timer.c b/examples/standalone/timer.c index 6628b21..834cc9a 100644 --- a/examples/standalone/timer.c +++ b/examples/standalone/timer.c @@ -115,7 +115,7 @@ void setPeriod (tid_8xx_cpmtimer_t *hwp, ulong interval); static char *usage = "\n[q, b, e, ?] "; -int timer (int argc, char *argv[]) +int timer (int argc, char * const argv[]) { cpmtimer8xx_t *cpmtimerp; /* Pointer to the CPM Timer structure */ tid_8xx_cpmtimer_t hw; |