diff --git a/crypto/test/file_util.cc b/crypto/test/file_util.cc index ede0d763fe..593a135f36 100644 --- a/crypto/test/file_util.cc +++ b/crypto/test/file_util.cc @@ -122,7 +122,9 @@ bool TemporaryFile::Init(bssl::Span content) { #else std::string path = temp_dir + "bssl_tmp_file.XXXXXX"; // TODO(davidben): Use |path.data()| when we require C++17. + mode_t prev_umask = umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); int fd = mkstemp(&path[0]); + umask(prev_umask); if (fd < 0) { perror("Could not create temporary file"); return false; diff --git a/crypto/test/file_util.h b/crypto/test/file_util.h index 57f306e721..376e151287 100644 --- a/crypto/test/file_util.h +++ b/crypto/test/file_util.h @@ -46,12 +46,15 @@ class ScopedFD { explicit ScopedFD(int fd) : fd_(fd) {} ~ScopedFD() { reset(); } - ScopedFD(ScopedFD &&other) { *this = std::move(other); } - ScopedFD &operator=(ScopedFD other) { + ScopedFD(ScopedFD &&other) noexcept { *this = std::move(other); } + ScopedFD &operator=(ScopedFD&& other) { reset(other.release()); return *this; } + ScopedFD(const ScopedFD &other) = delete; + ScopedFD &operator=(ScopedFD& other) = delete; + bool is_valid() const { return fd_ >= 0; } int get() const { return fd_; } @@ -85,7 +88,7 @@ class TemporaryFile { TemporaryFile() = default; ~TemporaryFile(); - TemporaryFile(TemporaryFile &other) { *this = std::move(other); } + TemporaryFile(TemporaryFile&& other) noexcept { *this = std::move(other); } TemporaryFile& operator=(TemporaryFile&&other) { // Ensure |path_| is empty so it doesn't try to delete the File. auto old_other_path = other.path_; @@ -94,6 +97,9 @@ class TemporaryFile { return *this; } + TemporaryFile(const TemporaryFile&) = delete; + TemporaryFile& operator=(const TemporaryFile&) = delete; + // Init initializes the temporary file with the specified content. It returns // true on success and false on error. On error, callers should call // |IgnoreTempFileErrors| to determine whether to ignore the error.