mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
bugfix: 修复shell中,用户可以删除多余的字符的bug,以及\b会被录入到参数字符串的bug
This commit is contained in:
@ -141,11 +141,19 @@ int shell_cmd_cd(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
goto fail;; // 出错则直接忽略
|
||||
goto fail;
|
||||
; // 出错则直接忽略
|
||||
}
|
||||
else
|
||||
{
|
||||
int new_len = current_dir_len + dest_len;
|
||||
int dest_offset = 0;
|
||||
if (dest_len > 2)
|
||||
{
|
||||
if (argv[1][0] == '.' && argv[1][1] == '/') // 相对路径
|
||||
dest_offset = 2;
|
||||
}
|
||||
|
||||
int new_len = current_dir_len + dest_len - dest_offset;
|
||||
// ======进入相对路径=====
|
||||
if (new_len >= SHELL_CWD_MAX_SIZE - 1)
|
||||
{
|
||||
@ -160,7 +168,7 @@ int shell_cmd_cd(int argc, char **argv)
|
||||
|
||||
if (current_dir_len > 1)
|
||||
new_path[current_dir_len] = '/';
|
||||
strcat(new_path, argv[1]);
|
||||
strcat(new_path, argv[1] + dest_offset);
|
||||
|
||||
if (chdir(new_path) == 0) // 成功切换目录
|
||||
{
|
||||
|
Reference in New Issue
Block a user