[Beignet] [PATCH 2/2] GBE: fixed the unsafe tmpnam_r.
Zhigang Gong
zhigang.gong at intel.com
Fri Feb 7 22:12:03 PST 2014
Use mkstemps instead.
Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
backend/src/backend/program.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 893cda3..2492a8b 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -652,13 +652,17 @@ namespace gbe {
char *err,
size_t *errSize)
{
- char clStr[L_tmpnam+1], llStr[L_tmpnam+1];
- const std::string clName = std::string(tmpnam_r(clStr)) + ".cl"; /* unsafe! */
- const std::string llName = std::string(tmpnam_r(llStr)) + ".ll"; /* unsafe! */
+ char clStr[] = "/tmp/XXXXXX.cl";
+ char llStr[] = "/tmp/XXXXXX.ll";
+ int clFd = mkstemps(clStr, 3);
+ int llFd = mkstemps(llStr, 3);
+ close(llFd);
+ const std::string clName = std::string(clStr);
+ const std::string llName = std::string(llStr);
std::string clOpt;
int optLevel = 1;
- FILE *clFile = fopen(clName.c_str(), "w");
+ FILE *clFile = fdopen(clFd, "w");
FATAL_IF(clFile == NULL, "Failed to open temporary file");
bool usePCH = OCL_USE_PCH;
--
1.7.9.5
More information about the Beignet
mailing list