diff options
author | Wolfgang Denk <wd@denx.de> | 2010-06-28 22:00:46 +0200 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2010-07-04 23:55:42 +0200 |
commit | 54841ab50c20d6fa6c9cc3eb826989da3a22d934 (patch) | |
tree | 400f22f0a12ff0ae6c472bed6ac648befc1744a2 /examples | |
parent | b218ccb5435e64ac2318bb8b6c9594ef1cc724cd (diff) | |
download | u-boot-54841ab50c20d6fa6c9cc3eb826989da3a22d934.tar.gz u-boot-54841ab50c20d6fa6c9cc3eb826989da3a22d934.tar.bz2 u-boot-54841ab50c20d6fa6c9cc3eb826989da3a22d934.zip |
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')
-rw-r--r-- | examples/api/demo.c | 2 | ||||
-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 |
12 files changed, 13 insertions, 13 deletions
diff --git a/examples/api/demo.c b/examples/api/demo.c index df9c4bd8bc..65e7491847 100644 --- a/examples/api/demo.c +++ b/examples/api/demo.c @@ -41,7 +41,7 @@ void test_dump_sig(struct api_signature *); static char buf[BUF_SZ]; -int main(int argc, char *argv[]) +int main(int argc, char * const argv[]) { int rv = 0, h, i, j, devs_no; struct api_signature *sig = NULL; diff --git a/examples/standalone/82559_eeprom.c b/examples/standalone/82559_eeprom.c index 5e2eee9e98..8dd7079ae7 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 db0cd693a9..b5b450317d 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 771a7e887e..3c7f380977 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 9317f6d8c0..067c39046d 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 f3061d1ec0..a5b58a1a08 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 f35f1ba5f6..d0a75eadfd 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 b91f34c3af..c98b0fc075 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 104047f5a5..c51a05028a 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 f3e1ab5c6a..2d2e7098b7 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 7109c098ef..2b101b74e6 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 6628b21de9..834cc9a49e 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; |