diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 587c3679b..12dd10c03 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +Fri Aug 3 13:04:00 2001 Corinna Vinschen + + * path.cc (fchdir): Set the fhandler's path to absolute value to + ensure changing to the correct directory even if the fhandler originally + points to a relative path. + Thu Aug 2 17:59:00 2001 Corinna Vinschen * security.cc (set_file_attribute): Clean up. Don't call diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 575d64f98..bd032d759 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3092,6 +3092,25 @@ fchdir (int fd) return -1; } int ret = chdir (cygheap->fdtab[fd]->get_name ()); + if (!ret) + { + /* The name in the fhandler is explicitely overwritten with the full path. + Otherwise fchmod() to a path originally given as a relative path could + end up in a completely different directory. Imagine: + + fd = open (".."); + fchmod(fd); + fchmod(fd); + + The 2nd fchmod should chdir to the same dir as the first call, not + to it's parent dir. */ + char path[MAX_PATH]; + char posix_path[MAX_PATH]; + mount_table->conv_to_posix_path (cygheap->cwd.get (path, 0, 1), + posix_path, 0); + cygheap->fdtab[fd]->set_name (path, posix_path); + } + syscall_printf ("%d = fchdir (%d)", ret, fd); return ret; }