-
Notifications
You must be signed in to change notification settings - Fork 7
Coverity: Set umask 0077 before creating tmp files #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||||||||||||||||||||||||||||
| #include <iostream> | ||||||||||||||||||||||||||||||||||||||
| #include <random> | ||||||||||||||||||||||||||||||||||||||
| #include <stdexcept> | ||||||||||||||||||||||||||||||||||||||
| #include <sys/stat.h> | ||||||||||||||||||||||||||||||||||||||
| #include <unistd.h> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| constexpr hipFileError_t | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,11 +63,17 @@ struct Tmpfile { | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Tmpfile(std::string directory) : path{directory} | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| // Security analyzers will be sad if you don't set umask 0077 | ||||||||||||||||||||||||||||||||||||||
| // before creating temporary files | ||||||||||||||||||||||||||||||||||||||
| mode_t old_umask = umask(S_IRWXG | S_IRWXO); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| path += "/hipFile.XXXXXX"; | ||||||||||||||||||||||||||||||||||||||
| if ((fd = mkstemp(path.data())) == -1) { | ||||||||||||||||||||||||||||||||||||||
| throw std::runtime_error("Could not create temporary file"); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| umask(old_umask); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+76
|
||||||||||||||||||||||||||||||||||||||
| mode_t old_umask = umask(S_IRWXG | S_IRWXO); | |
| path += "/hipFile.XXXXXX"; | |
| if ((fd = mkstemp(path.data())) == -1) { | |
| throw std::runtime_error("Could not create temporary file"); | |
| } | |
| umask(old_umask); | |
| struct UmaskGuard { | |
| mode_t old_umask; | |
| explicit UmaskGuard(mode_t new_mask) : old_umask(umask(new_mask)) {} | |
| ~UmaskGuard() { umask(old_umask); } | |
| } umask_guard(S_IRWXG | S_IRWXO); | |
| path += "/hipFile.XXXXXX"; | |
| if ((fd = mkstemp(path.data())) == -1) { | |
| throw std::runtime_error("Could not create temporary file"); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file uses
mode_t,umask(), andS_IRWXG/S_IRWXObut does not include<sys/stat.h>, which is where these are defined on POSIX systems. Please add#include <sys/stat.h>(or the appropriate header) to avoid build failures on stricter toolchains.