summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/ChangeLog.txt4
-rw-r--r--apps/nshlib/nsh_dbgcmds.c10
-rw-r--r--apps/nshlib/nsh_fscmds.c10
3 files changed, 21 insertions, 3 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index b957ca826..a0fae4402 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -889,4 +889,6 @@
* apps/system/nxplayer/nxplayer.c: Complilation failure in one
configuration reported by Manuel Stuhn (2014-4-21).
* apps/system/sdcard: Remove an STM32 dependency. From Bob Doiron
- (2014-4-21)
+ (2014-4-21).
+ * apps/nshlib: malloc/free IOBUFFER for 'cat' and 'hexdump' commands
+ instead of using the stack. From Bob Doiron (2014-4-21). \ No newline at end of file
diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c
index 15ce9498b..9f7ec205e 100644
--- a/apps/nshlib/nsh_dbgcmds.c
+++ b/apps/nshlib/nsh_dbgcmds.c
@@ -373,7 +373,7 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CONFIG_NSH_DISABLE_HEXDUMP
int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
- uint8_t buffer[IOBUFFERSIZE];
+ FAR uint8_t *buffer;
char msg[32];
off_t position;
int fd;
@@ -394,6 +394,13 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR;
}
+ buffer = (FAR uint8_t *)malloc(IOBUFFERSIZE);
+ if(buffer == NULL)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "malloc", NSH_ERRNO);
+ return ERROR;
+ }
+
#ifdef CONFIG_NSH_CMDOPT_HEXDUMP
for (x = 2; x < argc; x++)
{
@@ -489,6 +496,7 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
(void)close(fd);
+ free(buffer);
return ret;
}
#endif
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c
index 860e0b814..14e174243 100644
--- a/apps/nshlib/nsh_fscmds.c
+++ b/apps/nshlib/nsh_fscmds.c
@@ -416,7 +416,7 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
FAR const char *filename)
{
- char buffer[IOBUFFERSIZE];
+ FAR char *buffer;
int fd;
int ret = OK;
@@ -429,6 +429,13 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
return ERROR;
}
+ buffer = (FAR char *)malloc(IOBUFFERSIZE);
+ if(buffer == NULL)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, cmd, "malloc", NSH_ERRNO);
+ return ERROR;
+ }
+
/* And just dump it byte for byte into stdout */
for (;;)
@@ -514,6 +521,7 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
/* Close the input file and return the result */
(void)close(fd);
+ free(buffer);
return ret;
}
#endif