Skip to content

Commit

Permalink
Let include file name into error message when creation of temp file f…
Browse files Browse the repository at this point in the history
…ailed.
  • Loading branch information
hvlad committed Feb 10, 2021
1 parent f280502 commit fd0fa8a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/common/classes/TempFile.cpp
Expand Up @@ -135,6 +135,9 @@ PathName TempFile::create(const PathName& prefix, const PathName& directory)
// Creates a temporary file and returns its name.
// In error case store exception in status arg.
//
// Make sure exception will not be passed to the end-user as it
// contains server-side directory and it could break security!
//

PathName TempFile::create(CheckStatusWrapper* status, const PathName& prefix, const PathName& directory)
{
Expand Down Expand Up @@ -201,11 +204,18 @@ void TempFile::init(const PathName& directory, const PathName& prefix)
filename = name;
break;
}
const DWORD err = GetLastError();
if (err != ERROR_FILE_EXISTS)
{
(Arg::Gds(isc_io_error) << Arg::Str("CreateFile (create)") << Arg::Str(name) <<
Arg::Gds(isc_io_create_err) << Arg::OsError(err)).raise();
}
randomness++;
}
if (handle == INVALID_HANDLE_VALUE)
{
system_error::raise("CreateFile");
(Arg::Gds(isc_io_error) << Arg::Str("CreateFile (create)") << Arg::Str(filename) <<
Arg::Gds(isc_io_create_err) << Arg::OsError()).raise();
}
#else
filename += prefix;
Expand All @@ -216,15 +226,17 @@ void TempFile::init(const PathName& directory, const PathName& prefix)
#else
if (!mktemp(filename.begin()))
{
system_error::raise("mktemp");
(Arg::Gds(isc_io_error) << Arg::Str("mktemp") << Arg::Str(filename) <<
Arg::Gds(isc_io_create_err) << Arg::OsError()).raise();
}

handle = os_utils::open(filename.c_str(), O_RDWR | O_EXCL | O_CREAT);
#endif

if (handle == -1)
{
system_error::raise("open");
(Arg::Gds(isc_io_error) << Arg::Str("open") << Arg::Str(filename) <<
Arg::Gds(isc_io_create_err) << Arg::OsError()).raise();
}

if (doUnlink)
Expand Down

0 comments on commit fd0fa8a

Please sign in to comment.