diff --git a/crypto/bio/bio_test.cc b/crypto/bio/bio_test.cc index f908f279620..e76f3eb32fa 100644 --- a/crypto/bio/bio_test.cc +++ b/crypto/bio/bio_test.cc @@ -373,7 +373,7 @@ TEST(BIOTest, CloseFlags) { // Assert that CRLF line endings get inserted on write and translated back out // on read for text mode. - TempFILE text_bio_file(tmpfile()); + TempFILE text_bio_file = createTempFILE(); ASSERT_TRUE(text_bio_file); bssl::UniquePtr text_bio( BIO_new_fp(text_bio_file.get(), BIO_NOCLOSE | BIO_FP_TEXT)); @@ -403,7 +403,7 @@ TEST(BIOTest, CloseFlags) { // Assert that CRLF line endings don't get inserted on write for // (default) binary mode. - TempFILE binary_bio_file(tmpfile()); + TempFILE binary_bio_file = createTempFILE(); ASSERT_TRUE(binary_bio_file); bssl::UniquePtr binary_bio( BIO_new_fp(binary_bio_file.get(), BIO_NOCLOSE)); @@ -432,7 +432,7 @@ TEST(BIOTest, CloseFlags) { // Assert that BIO_CLOSE causes the underlying file to be closed on BIO free // (ftell will return < 0) - FILE *tmp = tmpfile(); + FILE *tmp = createRawTempFILE(); ASSERT_TRUE(tmp); BIO *bio = BIO_new_fp(tmp, BIO_CLOSE); EXPECT_EQ(0, BIO_tell(bio)); @@ -449,7 +449,7 @@ TEST(BIOTest, CloseFlags) { #endif // Assert that BIO_NOCLOSE does not close the underlying file on BIO free - tmp = tmpfile(); + tmp = createRawTempFILE(); ASSERT_TRUE(tmp); bio = BIO_new_fp(tmp, BIO_NOCLOSE); EXPECT_EQ(0, BIO_tell(bio)); @@ -737,7 +737,7 @@ TEST(BIOTest, Gets) { check_bio_gets(bio.get()); } - TempFILE file(tmpfile()); + TempFILE file = createTempFILE(); #if defined(OPENSSL_ANDROID) // On Android, when running from an APK, |tmpfile| does not work. See // b/36991167#comment8. diff --git a/crypto/dsa/dsa_test.cc b/crypto/dsa/dsa_test.cc index 104276b01c5..853e7b5a9c2 100644 --- a/crypto/dsa/dsa_test.cc +++ b/crypto/dsa/dsa_test.cc @@ -459,7 +459,7 @@ TEST(DSATest, DSAPrint) { #if !defined(OPENSSL_ANDROID) // On Android, when running from an APK, |tmpfile| does not work. See // b/36991167#comment8. - TempFILE tmp(tmpfile()); + TempFILE tmp = createTempFILE(); ASSERT_TRUE(tmp); ASSERT_TRUE(DSA_print_fp(tmp.get(), dsa.get(), 4)); fseek(tmp.get(), 0, SEEK_END); diff --git a/crypto/pem/pem_test.cc b/crypto/pem/pem_test.cc index 1f1abb8c368..390b74938d3 100644 --- a/crypto/pem/pem_test.cc +++ b/crypto/pem/pem_test.cc @@ -88,7 +88,7 @@ TEST(PEMTest, WriteReadASN1IntegerPem) { ASSERT_TRUE(ASN1_INTEGER_set(asn1_int.get(), original_value)); // Create buffer for writing - TempFILE pem_file(tmpfile()); + TempFILE pem_file = createTempFILE(); ASSERT_TRUE(pem_file); // Write the ASN1_INTEGER to a PEM-formatted string diff --git a/crypto/rsa_extra/rsa_test.cc b/crypto/rsa_extra/rsa_test.cc index 8ed654e244a..c49ed26bec1 100644 --- a/crypto/rsa_extra/rsa_test.cc +++ b/crypto/rsa_extra/rsa_test.cc @@ -1450,7 +1450,7 @@ TEST(RSATest, PrintBio) { #if !defined(OPENSSL_ANDROID) // On Android, when running from an APK, |tmpfile| does not work. See // b/36991167#comment8. - TempFILE tmp(tmpfile()); + TempFILE tmp = createTempFILE(); ASSERT_TRUE(tmp); ASSERT_TRUE(RSA_print_fp(tmp.get(), rsa.get(), 4)); fseek(tmp.get(), 0, SEEK_END); diff --git a/crypto/test/test_util.cc b/crypto/test/test_util.cc index dfbe5369827..33c6b618bd1 100644 --- a/crypto/test/test_util.cc +++ b/crypto/test/test_util.cc @@ -86,3 +86,27 @@ bssl::UniquePtr CertFromPEM(const char *pem) { return bssl::UniquePtr( PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr)); } + +#if defined(OPENSSL_WINDOWS) +#include +FILE* createRawTempFILE() { + char pathname[PATH_MAX]; + if(0 == GetTempPathA(PATH_MAX, pathname)) { + return nullptr; + } + char filename[PATH_MAX]; + if(0 == GetTempFileNameA(pathname, "awslctest", 0, filename)) { + return nullptr; + } + return fopen(filename, "w+b"); +} +#else +#include +FILE* createRawTempFILE() { + return tmpfile(); +} +#endif + +TempFILE createTempFILE() { + return TempFILE(createRawTempFILE()); +} \ No newline at end of file diff --git a/crypto/test/test_util.h b/crypto/test/test_util.h index 4c6436e7182..bf906c490b3 100644 --- a/crypto/test/test_util.h +++ b/crypto/test/test_util.h @@ -82,4 +82,7 @@ struct FileCloser { using TempFILE = std::unique_ptr; +FILE* createRawTempFILE(); +TempFILE createTempFILE(); + #endif // OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H