Explorar el Código

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

When using musl libc's strcat, strcat itself will cause system crash.
Meco Man hace 1 año
padre
commit
1ea1c8fc7b
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  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;
 }