Skip to content

Commit

Permalink
Limit use of deprecated tmpnam function
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth authored and justinwsmith committed Mar 22, 2024
1 parent d4b3a4c commit ec49a15
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions crypto/test/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,31 @@ size_t createTempFILEpath(char buffer[PATH_MAX]) {
}
return GetTempFileNameA(pathname, "awslctest", 0, buffer);
}
FILE* createRawTempFILE() {
char filename[PATH_MAX];
if(createTempFILEpath(filename) == 0) {
return nullptr;
}
return fopen(filename, "w+b");
}
#else
#include <cstdlib>
size_t createTempFILEpath(char buffer[PATH_MAX]) {
if(tmpnam(buffer) == nullptr) {
OPENSSL_BEGIN_ALLOW_DEPRECATED
OPENSSL_STATIC_ASSERT(PATH_MAX >= L_tmpnam, PATH_MAX_too_short);
// Functions for constructing a tempfile path (i.e., tmpname and mktemp)
// are deprecated in C99.
if(nullptr == tmpnam(buffer)) {
return 0;
}
OPENSSL_END_ALLOW_DEPRECATED
return strnlen(buffer, PATH_MAX);
}
#endif

FILE* createRawTempFILE() {
char filename[PATH_MAX];
if(createTempFILEpath(filename) == 0) {
return nullptr;
}
return fopen(filename, "w+b");
return tmpfile();
}
#endif


TempFILE createTempFILE() {
return TempFILE(createRawTempFILE());
Expand Down

0 comments on commit ec49a15

Please sign in to comment.