changeset 1605:43a89c18d005

Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
author gthomas
date Fri, 23 Apr 2004 20:38:17 +0000
parents bc88a3357a79
children 6afeeb154176
files packages/redboot/current/ChangeLog packages/redboot/current/include/redboot.h packages/redboot/current/src/flash.c packages/redboot/current/src/fs/fileio.c packages/redboot/current/src/load.c packages/redboot/current/src/main.c packages/redboot/current/src/net/net_io.c packages/redboot/current/src/net/tftp_client.c
diffstat 8 files changed, 43 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog
+++ b/packages/redboot/current/ChangeLog
@@ -1,3 +1,18 @@
+2004-04-23  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/main.c: 
+	* src/fs/fileio.c: 
+	* src/net/net_io.c: 
+	* src/load.c: 
+	* src/flash.c: 
+	* include/redboot.h: Add asserts to check that option arrays
+	are not overrun (when used with variable number of options).
+
+2004-04-23  Gary Parnes  <garyp@logicpd.com>
+
+	* src/net/tftp_client.c: The port, if specified by the user,
+	is now corrected for endianness issues.
+
 2004-04-19  Gary Thomas  <gary@mlbassoc.com>
 
 	* src/fs/fileio.c: Can't test for CYGPKG_IO_FLASH_BLOCK_DEVICE without
--- a/packages/redboot/current/include/redboot.h
+++ b/packages/redboot/current/include/redboot.h
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002, 2003 Gary Thomas
+// Copyright (C) 2002, 2003, 2004 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -295,6 +295,8 @@ struct option_info {
     char *name;
 };
 
+#define NUM_ELEMS(s) (sizeof(s)/sizeof(s[0]))
+
 #define OPTION_ARG_TYPE_NUM 0    // Numeric data
 #define OPTION_ARG_TYPE_STR 1    // Generic string
 #define OPTION_ARG_TYPE_FLG 2    // Flag only
--- a/packages/redboot/current/src/flash.c
+++ b/packages/redboot/current/src/flash.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2003 Gary Thomas
+// Copyright (C) 2003, 2004 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -57,6 +57,7 @@
 #include <cyg/io/flash.h>
 #include <fis.h>
 #include <sib.h>
+#include <cyg/infra/cyg_ass.h>         // assertion macros
 
 #ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
 // Note horrid intertwining of functions, to save precious FLASH
@@ -1002,6 +1003,8 @@ fis_load(int argc, char *argv[])
     num_options++;
 #endif
 
+    CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
+
     if (!scan_opts(argc, argv, 2, opts, num_options, (void *)&name, OPTION_ARG_TYPE_STR, "image name"))
     {
         fis_usage("invalid arguments");
--- a/packages/redboot/current/src/fs/fileio.c
+++ b/packages/redboot/current/src/fs/fileio.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002, 2003 Gary Thomas
+// Copyright (C) 2002, 2003, 2004 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -69,6 +69,7 @@
 #include <cyg/io/config_keys.h>
 #endif
 #include <cyg/fileio/fileio.h>
+#include <cyg/infra/cyg_ass.h>         // assertion macros
 
 static void do_mount(int argc, char *argv[]);
 static void do_umount(int argc, char *argv[]);
@@ -111,6 +112,8 @@ do_mount(int argc, char *argv[])
     num_opts++;
 #endif
 
+    CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");
+
     if (!scan_opts(argc, argv, 1, opts, num_opts, NULL, 0, NULL))
         return;
 
--- a/packages/redboot/current/src/load.c
+++ b/packages/redboot/current/src/load.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002, 2003 Gary Thomas
+// Copyright (C) 2002, 2003, 2004 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -72,6 +72,7 @@
 #include <net/http.h>
 #endif
 #endif
+#include <cyg/infra/cyg_ass.h>         // assertion macros
 
 static char usage[] = "[-r] [-v] "
 #ifdef CYGBLD_BUILD_REDBOOT_WITH_ZLIB
@@ -599,7 +600,7 @@ do_load(int argc, char *argv[])
     unsigned long end = 0;
     char type[4];
     char *filename = 0;
-    struct option_info opts[7];
+    struct option_info opts[8];
     connection_info_t info;
     getc_io_funcs_t *io = NULL;
     struct load_io_entry *io_tab;
@@ -644,6 +645,8 @@ do_load(int argc, char *argv[])
     num_options++;
 #endif
 
+    CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
+    
     if (!scan_opts(argc, argv, 1, opts, num_options, 
                    (void *)&filename, OPTION_ARG_TYPE_STR, "file name")) {
         return;
--- a/packages/redboot/current/src/main.c
+++ b/packages/redboot/current/src/main.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002, 2003 Gary Thomas
+// Copyright (C) 2002, 2003, 2004 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -66,6 +66,7 @@
 #endif
 
 #include <cyg/hal/hal_tables.h>
+#include <cyg/infra/cyg_ass.h>         // assertion macros
 
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
 #ifdef CYGBLD_HAL_PLATFORM_STUB_H
@@ -536,6 +537,9 @@ do_go(int argc, char *argv[])
               (void *)&stop_net, (bool *)0, "go with network driver stopped");
     num_options++;
 #endif
+
+    CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
+
     if (!scan_opts(argc, argv, 1, opts, num_options, (void *)&entry, OPTION_ARG_TYPE_NUM, "starting address"))
     {
         return;
--- a/packages/redboot/current/src/net/net_io.c
+++ b/packages/redboot/current/src/net/net_io.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002, 2003 Gary Thomas
+// Copyright (C) 2002, 2003, 2004 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -59,6 +59,7 @@
 #include <cyg/hal/hal_if.h>     // HAL I/O interfaces
 #include <cyg/hal/drv_api.h>
 #include <cyg/hal/hal_intr.h>
+#include <cyg/infra/cyg_ass.h>         // assertion macros
 
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
 #include <flash_config.h>
@@ -806,6 +807,9 @@ do_ip_addr(int argc, char *argv[])
               (void *)&dns_addr, (bool *)&dns_addr_set, "DNS server address");
     num_opts++;
 #endif
+
+    CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");
+
     if (!scan_opts(argc, argv, 1, opts, num_opts, 0, 0, "")) {
         return;
     }
--- a/packages/redboot/current/src/net/tftp_client.c
+++ b/packages/redboot/current/src/net/tftp_client.c
@@ -105,6 +105,8 @@ tftp_stream_open(connection_info_t *info
 
     if (info->server->sin_port == 0) {
         info->server->sin_port = htons(TFTP_PORT);
+    } else {
+        info->server->sin_port = htons(info->server->sin_port);
     }
 
     // Send request - note: RFC 1350 (TFTP rev 2) indicates that this should be