apps/nshlib/cmd_cd: Modify the logic of cd

Modify the implementation logic of changing directory.
There's an error handling the path incluing "../" or "./"

bug examples:

nsh> cd proc/self/group
nsh> cd ../..
nsh: cd: chdir failed: 2

nsh> pwd
/proc/self
nsh> ls
/proc/self:
 status
 cmdline
 stack
 group/
nsh> cd ./group
nsh: cd: chdir failed: 2

Signed-off-by: zhengyu9 <zhengyu9@xiaomi.com>
This commit is contained in:
zhengyu9
2024-06-20 17:55:23 +08:00
committed by Xiang Xiao
parent 59c21c7aee
commit 697e3bed0a

View File

@@ -583,7 +583,7 @@ FAR char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl,
snprintf(vtbl->iobuffer, IOBUFFERSIZE, "%s/%s", dirpath, path);
}
return strdup(vtbl->iobuffer);
return lib_realpath(vtbl->iobuffer, NULL, true);
}
#endif