summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2024-03-27 18:39:40 -0400
committerMeco Man <[email protected]>2024-03-27 18:40:56 -0400
commite0f2313c534eda75512d7b07398de3e72292209d (patch)
tree179f08b50fa4d01bfbb00ac471d01591f2757ae3
parent61c1041d47153c1b53ed92bfe5a09f1da55a350b (diff)
[msh] solve data access bugs and fix shell.c strcat()
When using musl libc's strcat, strcat itself will cause system crash.
-rw-r--r--components/finsh/shell.c6
1 files changed, 5 insertions, 1 deletions
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;
}