From 1ea1c8fc7bacd167c3041ab088dba031dca456b4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 27 Mar 2024 18:39:40 -0400 Subject: [PATCH] [msh] solve data access bugs and fix shell.c strcat() When using musl libc's strcat, strcat itself will cause system crash. --- components/finsh/shell.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index b21b314525..e698edd51f 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -112,7 +112,11 @@ const char *finsh_get_prompt(void) getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt)); #endif - strcat(finsh_prompt, ">"); + if (rt_strlen(finsh_prompt) + 2 < RT_CONSOLEBUF_SIZE) + { + finsh_prompt[rt_strlen(finsh_prompt)] = '>'; + finsh_prompt[rt_strlen(finsh_prompt) + 1] = '\0'; + } return finsh_prompt; }