Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Ensure *at function does not mess up with cwd
Baptiste Daroussin committed 11 years ago
commit f436491a4dced5a6dab9f2e3d496f392292bd61a
parent 642e0d2
2 files changed +15 -1
modified compat/file_at.c
@@ -24,6 +24,8 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#include <sys/param.h>
+

#include <bsd_compat.h>
#include <assert.h>
#include <fcntl.h>
@@ -35,6 +37,7 @@

static pthread_mutex_t file_at_lock = PTHREAD_MUTEX_INITIALIZER;
static int file_at_dfd = -1;
+
static char saved_cwd[MAXPATHLEN];

/**
 * Acquire the cwd mutex and perform fchdir(dfd).
@@ -53,6 +56,9 @@ file_chdir_lock(int dfd)

	pthread_mutex_lock(&file_at_lock);

+
	if (getcwd(saved_cwd, sizeof(saved_cwd)) == NULL)
+
		saved_cwd[0] = '\0';
+

	assert(file_at_dfd == -1);
	file_at_dfd = dfd;

@@ -80,6 +86,8 @@ file_chdir_unlock(int dfd)
	if (dfd == AT_FDCWD)
		return;

+
	if (saved_cwd[0] != '\0')
+
		chdir(saved_cwd);
	pthread_mutex_unlock(&file_at_lock);
}
#endif
@@ -89,6 +97,11 @@ int
faccessat(int fd, const char *path, int mode, int flag)
{
	int ret;
+
	char saved_cwd[MAXPATHLEN];
+
	const char *cwd;
+

+
	if ((cwd = getcwd(saved_cwd, sizeof(saved_cwd))) == NULL)
+
		return (-1);

	if ((ret = file_chdir_lock(fd) != 0))
		return ret;
modified tests/frontend/pkg.shin
@@ -80,10 +80,11 @@ EOF
	    -e inline:"pkg: Skipping malformed key 'files'\n" \
	    -s exit:0 \
	    pkg create -q -m testpkg/.metadir -r testpkg
+

	atf_check \
	    -o empty \
	    -e empty \
-
	    -s exit:1 \
+
	    -s exit:0 \
	    test -f test-1.txz
}