Use umask() to Constrain Created File Permissions
This commit addresses #2491. Note that a downside of this solution is that it is global: `umask()` affects all file creation calls in the process. I believe this is safe since `fileio.c` functions should only ever be used in the zstd binary, and these are (almost) the only files ever created by zstd, and AIUI they're only created in a single thread. So we can get away with messing with global state. Note that this doesn't change the permissions of files created by `dibio.c`. I'm not sure what those should be...
This commit is contained in:
+3
-6
@@ -679,14 +679,11 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
||||
FIO_removeFile(dstFileName);
|
||||
} }
|
||||
|
||||
{ FILE* const f = fopen( dstFileName, "wb" );
|
||||
{ const int old_umask = UTIL_umask(0177); /* u-x,go-rwx */
|
||||
FILE* const f = fopen( dstFileName, "wb" );
|
||||
UTIL_umask(old_umask);
|
||||
if (f == NULL) {
|
||||
DISPLAYLEVEL(1, "zstd: %s: %s\n", dstFileName, strerror(errno));
|
||||
} else if (srcFileName != NULL
|
||||
&& strcmp (srcFileName, stdinmark)
|
||||
&& strcmp(dstFileName, nulmark) ) {
|
||||
/* reduce rights on newly created dst file while compression is ongoing */
|
||||
UTIL_chmod(dstFileName, NULL, 00600);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user