Skip to content

Commit 343c059

Browse files
committed
fix potential non-zero termination of a string buffer
1 parent 41d7a45 commit 343c059

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/util/tempdir.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: CM Wintersteiger
1212
#include <windows.h>
1313
#include <io.h>
1414
#include <direct.h>
15+
#else
16+
#include <vector>
1517
#endif
1618

1719
#include <cstdlib>
@@ -64,9 +66,11 @@ std::string get_temporary_directory(const std::string &name_template)
6466
prefixed_name_template+='/';
6567
prefixed_name_template+=name_template;
6668

67-
char t[1000];
68-
strncpy(t, prefixed_name_template.c_str(), 1000);
69-
const char *td = mkdtemp(t);
69+
std::vector<char> t;
70+
// add one byte for the zero
71+
t.resize(prefixed_name_template.size()+1);
72+
memcpy(t.data(), prefixed_name_template.c_str(), t.size());
73+
const char *td = mkdtemp(t.data());
7074
if(!td)
7175
throw "mkdtemp failed";
7276
result=std::string(td);

0 commit comments

Comments
 (0)