瀏覽代碼

[msh] solve data access bugs and fix shell.c strcat()

When using musl libc's strcat, strcat itself will cause system crash.
Meco Man 1 年之前
父節點
當前提交
1ea1c8fc7b
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      components/finsh/shell.c

+ 5 - 1
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;
 }