From ce3c604f48c8217fefdccf649da314bbc5901ee6 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Fri, 11 Feb 2022 16:15:01 +0800 Subject: [PATCH] libc/chdir:"PWD" should save absolute path Signed-off-by: anjiahao --- libs/libc/unistd/lib_chdir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/libc/unistd/lib_chdir.c b/libs/libc/unistd/lib_chdir.c index 20111b61eb..020027e801 100644 --- a/libs/libc/unistd/lib_chdir.c +++ b/libs/libc/unistd/lib_chdir.c @@ -100,6 +100,7 @@ int chdir(FAR const char *path) struct stat buf; char *oldpwd; char *alloc; + char *abspath; int errcode; int ret; @@ -151,7 +152,15 @@ int chdir(FAR const char *path) /* Set the cwd to the input 'path' */ - setenv("PWD", path, TRUE); + abspath = realpath(path, NULL); + if (abspath == NULL) + { + errcode = ENOENT; + goto errout; + } + + setenv("PWD", abspath, TRUE); + lib_free(abspath); sched_unlock(); return OK;