diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2008-05-19 20:22:29 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2008-05-19 20:22:29 +0000 |
commit | 78ee2ae11faa2e63ee909541bdc0d9ddb3a09429 (patch) | |
tree | 462065edf8f8ba215aae6027253ef4352d9267f3 | |
parent | a4e3764e5152c1a526fa673fe8a36278b8642f47 (diff) | |
download | cygnal-78ee2ae11faa2e63ee909541bdc0d9ddb3a09429.tar.gz cygnal-78ee2ae11faa2e63ee909541bdc0d9ddb3a09429.tar.bz2 cygnal-78ee2ae11faa2e63ee909541bdc0d9ddb3a09429.zip |
* syscalls.cc (rename): Allocate temporary path buffers using
tmp_pathbuf. Don't try to unset R/O attribute on dstpc if a
removepc exists. dstpc is a non-existant file in that case.
-rw-r--r-- | winsup/cygwin/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 16 |
2 files changed, 17 insertions, 5 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 6cca20af2..90c031fcc 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2008-05-19 Corinna Vinschen <corinna@vinschen.de> + + * syscalls.cc (rename): Allocate temporary path buffers using + tmp_pathbuf. Don't try to unset R/O attribute on dstpc if a + removepc exists. dstpc is a non-existant file in that case. + 2008-05-17 Christopher Faylor <me+cygwin@cgf.cx> * include/stdint.h: Use int rather than long for {u,}int32_t. diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 4f35b6b69..82f745bb8 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1494,6 +1494,7 @@ stop_transaction (NTSTATUS status, HANDLE old_trans, HANDLE trans) extern "C" int rename (const char *oldpath, const char *newpath) { + tmp_pathbuf tp; int res = -1; char *oldbuf, *newbuf; path_conv oldpc, newpc, new2pc, *dstpc, *removepc = NULL; @@ -1533,7 +1534,7 @@ rename (const char *oldpath, const char *newpath) olen = strlen (oldpath); if (isdirsep (oldpath[olen - 1])) { - stpcpy (oldbuf = (char *) alloca (olen + 1), oldpath); + stpcpy (oldbuf = tp.c_get (), oldpath); while (olen > 0 && isdirsep (oldbuf[olen - 1])) oldbuf[--olen] = '\0'; oldpath = oldbuf; @@ -1568,7 +1569,7 @@ rename (const char *oldpath, const char *newpath) nlen = strlen (newpath); if (isdirsep (newpath[nlen - 1])) { - stpcpy (newbuf = (char *) alloca (nlen + 1), newpath); + stpcpy (newbuf = tp.c_get (), newpath); while (nlen > 0 && isdirsep (newbuf[nlen - 1])) newbuf[--nlen] = '\0'; newpath = newbuf; @@ -1746,8 +1747,10 @@ rename (const char *oldpath, const char *newpath) } } /* You can't copy a file if the destination exists and has the R/O - attribute set. Remove the R/O attribute first. */ - else if (dstpc->has_attribute (FILE_ATTRIBUTE_READONLY)) + attribute set. Remove the R/O attribute first. But first check + if a removepc exists. If so, dstpc points to a non-existing file + due to a mangled suffix. */ + else if (!removepc && dstpc->has_attribute (FILE_ATTRIBUTE_READONLY)) { status = NtOpenFile (&nfh, FILE_WRITE_ATTRIBUTES, dstpc->get_object_attr (attr, sec_none_nih), @@ -1814,7 +1817,10 @@ rename (const char *oldpath, const char *newpath) } size = sizeof (FILE_RENAME_INFORMATION) + dstpc->get_nt_native_path ()->Length; - pfri = (PFILE_RENAME_INFORMATION) alloca (size); + if (size > NT_MAX_PATH * sizeof (WCHAR)) /* Hopefully very seldom. */ + pfri = (PFILE_RENAME_INFORMATION) alloca (size); + else + pfri = (PFILE_RENAME_INFORMATION) tp.w_get (); pfri->ReplaceIfExists = TRUE; pfri->RootDirectory = NULL; pfri->FileNameLength = dstpc->get_nt_native_path ()->Length; |