From 7129694f381a5bbf825f3ad613d072812f45f509 Mon Sep 17 00:00:00 2001 From: David Lin Date: Fri, 12 Jun 2020 08:49:46 +0800 Subject: [PATCH 1/2] [finsh]Fixed a bug may cause stackover flow add code: if (line_buf == RT_NULL) return -RT_ENOMEM; --- components/finsh/msh_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c index 10251b4cb5..38519ce7a9 100644 --- a/components/finsh/msh_file.c +++ b/components/finsh/msh_file.c @@ -101,6 +101,7 @@ int msh_exec_script(const char *cmd_line, int size) int length; line_buf = (char *) rt_malloc(RT_CONSOLEBUF_SIZE); + if (line_buf == RT_NULL) return -RT_ENOMEM; /* read line by line and then exec it */ do From 5bb38bb4e8110ed0e1b688969814d2b8bb78478f Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 13 Jun 2020 10:13:51 +0800 Subject: [PATCH 2/2] Update msh_file.c --- components/finsh/msh_file.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c index 38519ce7a9..10025965f0 100644 --- a/components/finsh/msh_file.c +++ b/components/finsh/msh_file.c @@ -101,7 +101,11 @@ int msh_exec_script(const char *cmd_line, int size) int length; line_buf = (char *) rt_malloc(RT_CONSOLEBUF_SIZE); - if (line_buf == RT_NULL) return -RT_ENOMEM; + if (line_buf == RT_NULL) + { + close(fd); + return -RT_ENOMEM; + } /* read line by line and then exec it */ do