mirror of
https://github.com/znc/znc.git
synced 2026-08-09 02:12:56 +02:00
fileutils: force owner write while copying read-only sources
Opening the destination at the source's exact mode breaks when the source lacks owner write (e.g. r-xr-xr-x): the create still works but the overwrite path can't reopen such a destination for writing. Force owner read+write while copying and let the trailing Chmod() put the source mode back, which only ever adds owner bits so the group/other bits stay as restrictive as the source throughout. Add a regression test covering the restricted-mode and read-only-source cases.
This commit is contained in:
+5
-1
@@ -265,7 +265,11 @@ bool CFile::Copy(const CString& sOldFileName, const CString& sNewFileName,
|
||||
iMode = st.st_mode & 07777;
|
||||
}
|
||||
|
||||
if (!NewFile.Open(O_WRONLY | O_CREAT | O_TRUNC, iMode)) {
|
||||
// Force owner read+write while copying so the write still works for a
|
||||
// source that lacks them (e.g. r-xr-xr-x); the trailing Chmod() puts
|
||||
// the exact source mode back. This only ever adds owner bits, so the
|
||||
// group/other bits stay as restrictive as the source the whole time.
|
||||
if (!NewFile.Open(O_WRONLY | O_CREAT | O_TRUNC, iMode | S_IRUSR | S_IWUSR)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user