Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{bp-15120} libc/chdir: chdir/fchdir should not depend on environment variables #15134

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libs/libc/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ set(SRCS
lib_getpgid.c
lib_lockf.c
lib_flock.c
lib_getpass.c)
lib_getpass.c
lib_chdir.c
lib_fchdir.c)

if(NOT CONFIG_SCHED_USER_IDENTITY)
list(
Expand All @@ -83,7 +85,7 @@ if(NOT CONFIG_SCHED_USER_IDENTITY)
endif()

if(NOT CONFIG_DISABLE_ENVIRON)
list(APPEND SRCS lib_chdir.c lib_fchdir.c lib_restoredir.c)
list(APPEND SRCS lib_restoredir.c)
endif()

if(CONFIG_LIBC_EXECFUNCS)
Expand Down
3 changes: 2 additions & 1 deletion libs/libc/unistd/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ CSRCS += lib_futimes.c lib_lutimes.c lib_gethostname.c lib_sethostname.c
CSRCS += lib_fchownat.c lib_linkat.c lib_readlinkat.c lib_symlinkat.c
CSRCS += lib_unlinkat.c lib_usleep.c lib_getpgrp.c lib_getpgid.c
CSRCS += lib_lockf.c lib_flock.c lib_getpass.c
CSRCS += lib_chdir.c lib_fchdir.c

ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
CSRCS += lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c
endif

ifneq ($(CONFIG_DISABLE_ENVIRON),y)
CSRCS += lib_chdir.c lib_fchdir.c lib_restoredir.c
CSRCS += lib_restoredir.c
endif

ifeq ($(CONFIG_LIBC_EXECFUNCS),y)
Expand Down
11 changes: 7 additions & 4 deletions libs/libc/unistd/lib_chdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

#include "libc.h"

#ifndef CONFIG_DISABLE_ENVIRON

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -74,9 +72,11 @@

int chdir(FAR const char *path)
{
struct stat buf;
#ifndef CONFIG_DISABLE_ENVIRON
FAR char *oldpwd;
#endif /* !CONFIG_DISABLE_ENVIRON */
FAR char *abspath;
struct stat buf;
int ret;

/* Verify that 'path' refers to a directory */
Expand Down Expand Up @@ -105,6 +105,8 @@ int chdir(FAR const char *path)
return ERROR;
}

#ifndef CONFIG_DISABLE_ENVIRON

/* Replace any preceding OLDPWD with the current PWD (this is to
* support 'cd -' in NSH)
*/
Expand All @@ -120,8 +122,9 @@ int chdir(FAR const char *path)
/* Set the cwd to the input 'path' */

ret = setenv("PWD", abspath, TRUE);
#endif /* !CONFIG_DISABLE_ENVIRON */

lib_free(abspath);

return ret;
}
#endif /* !CONFIG_DISABLE_ENVIRON */
4 changes: 0 additions & 4 deletions libs/libc/unistd/lib_fchdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#include <unistd.h>
#include <nuttx/lib/lib.h>

#ifndef CONFIG_DISABLE_ENVIRON

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -89,5 +87,3 @@ int fchdir(int fd)
lib_put_pathbuffer(path);
return ret;
}

#endif /* !CONFIG_DISABLE_ENVIRON */
Loading