This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: Fixes to RedBoot "load" command
- From: Gary Thomas <gary at mlbassoc dot com>
- To: Gary Parnes <GaryP at logicpd dot com>
- Cc: eCos patches <ecos-patches at ecos dot sourceware dot org>
- Date: Fri, 23 Apr 2004 14:38:25 -0600
- Subject: Re: Fixes to RedBoot "load" command
- Organization: MLB Associates
- References: <31ADFA827355984B9E2A161514595B560E41A5@lpdsrv04.logicpd.com>
On Fri, 2004-04-23 at 13:43, Gary Parnes wrote:
> Two fixes concerning RedBoot's "load" command in this patch. One corrects a
> potential stack corruption situation. The other fixes a problem when
> specifying the port on a little endian system.
>
>
> <<redboot_patch.txt>>
Thanks for pointing these out. I've committed the change to the TFTP
code as-is. The change for 'load' was rather messy so I did it a little
differently. I also went ahead and made the same change everywhere that
a variable option list was used.
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.192
diff -u -5 -p -r1.192 ChangeLog
--- redboot/current/ChangeLog 19 Apr 2004 21:26:52 -0000 1.192
+++ redboot/current/ChangeLog 23 Apr 2004 20:33:58 -0000
@@ -1,5 +1,20 @@
+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
first testing for CYGPKG_IO_FLASH and including it's pkgconf file.
Index: redboot/current/include/redboot.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/redboot.h,v
retrieving revision 1.31
diff -u -5 -p -r1.31 redboot.h
--- redboot/current/include/redboot.h 15 Oct 2003 15:52:03 -0000 1.31
+++ redboot/current/include/redboot.h 23 Apr 2004 20:29:07 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// 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
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -292,10 +292,12 @@ struct option_info {
int arg_type;
void *arg;
bool *arg_set;
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
Index: redboot/current/src/flash.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.64
diff -u -5 -p -r1.64 flash.c
--- redboot/current/src/flash.c 24 Feb 2004 14:15:15 -0000 1.64
+++ redboot/current/src/flash.c 23 Apr 2004 20:30:44 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// 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
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -55,10 +55,11 @@
#include <redboot.h>
#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
#endif
@@ -999,10 +1000,12 @@ fis_load(int argc, char *argv[])
#ifdef CYGPRI_REDBOOT_ZLIB_FLASH
init_opts(&opts[num_options], 'd', false, OPTION_ARG_TYPE_FLG,
(void *)&decompress, 0, "decompress");
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");
return;
Index: redboot/current/src/load.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/load.c,v
retrieving revision 1.41
diff -u -5 -p -r1.41 load.c
--- redboot/current/src/load.c 18 Mar 2004 14:26:57 -0000 1.41
+++ redboot/current/src/load.c 23 Apr 2004 20:25:43 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// 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
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -70,10 +70,11 @@
#endif
#ifdef CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
#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
"[-d] "
#endif
@@ -597,11 +598,11 @@ do_load(int argc, char *argv[])
#endif
unsigned long base = 0;
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;
unsigned int port; //int because it's an OPTION_ARG_TYPE_NUM, but will be cast to short
#ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
@@ -642,10 +643,12 @@ do_load(int argc, char *argv[])
init_opts(&opts[num_options], 'd', false, OPTION_ARG_TYPE_FLG,
(void *)&decompress, 0, "decompress");
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;
}
#ifdef CYGPKG_REDBOOT_NETWORKING
Index: redboot/current/src/main.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/main.c,v
retrieving revision 1.56
diff -u -5 -p -r1.56 main.c
--- redboot/current/src/main.c 24 Feb 2004 14:15:15 -0000 1.56
+++ redboot/current/src/main.c 23 Apr 2004 20:32:54 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// 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
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -64,10 +64,11 @@
#ifdef CYGPKG_IO_ETH_DRIVERS
#include <cyg/io/eth/eth_drv.h> // Logical driver interfaces
#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
#include CYGBLD_HAL_PLATFORM_STUB_H
#else
@@ -534,10 +535,13 @@ do_go(int argc, char *argv[])
#ifdef CYGPKG_IO_ETH_DRIVERS
init_opts(&opts[2], 'n', false, OPTION_ARG_TYPE_FLG,
(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;
}
if (entry == (unsigned long)NO_MEMORY) {
Index: redboot/current/src/fs/fileio.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/fs/fileio.c,v
retrieving revision 1.3
diff -u -5 -p -r1.3 fileio.c
--- redboot/current/src/fs/fileio.c 19 Apr 2004 21:26:52 -0000 1.3
+++ redboot/current/src/fs/fileio.c 23 Apr 2004 20:32:52 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// 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
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -67,10 +67,11 @@
#include <cyg/io/io.h>
#include <cyg/io/flash.h>
#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[]);
#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
@@ -108,10 +109,12 @@ do_mount(int argc, char *argv[])
#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
init_opts(&opts[2], 'f', true, OPTION_ARG_TYPE_STR,
(void *)&part_str, &part_set, "partition");
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;
if (!type_set) {
Index: redboot/current/src/net/net_io.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/net_io.c,v
retrieving revision 1.38
diff -u -5 -p -r1.38 net_io.c
--- redboot/current/src/net/net_io.c 24 Feb 2004 14:15:15 -0000 1.38
+++ redboot/current/src/net/net_io.c 23 Apr 2004 20:32:51 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// 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
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -57,10 +57,11 @@
#include <net/net.h>
#include <cyg/hal/hal_misc.h> // Helper functions
#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>
RedBoot_config_option("GDB connection port",
@@ -804,10 +805,13 @@ do_ip_addr(int argc, char *argv[])
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS
init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_STR,
(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;
}
if (ip_addr_set) {
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
Index: redboot/current/src/net/tftp_client.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/tftp_client.c,v
retrieving revision 1.15
diff -u -5 -p -r1.15 tftp_client.c
--- redboot/current/src/net/tftp_client.c 19 Sep 2003 17:11:34 -0000 1.15
+++ redboot/current/src/net/tftp_client.c 23 Apr 2004 20:27:49 -0000
@@ -103,10 +103,12 @@ tftp_stream_open(connection_info_t *info
tftp_stream.local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
tftp_stream.local_addr.sin_port = htons(get_port++);
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
// only as long as required to hold the request, with the nul terminator.
// Some servers silently go to lunch if the request is not the correct size.