Skip to content

Commit 1059b35

Browse files
author
Daniel Kroening
committed
fix potential non-zero termination of a string buffer
1 parent 41d7a45 commit 1059b35

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/util/tempdir.cpp

Lines changed: 5 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,9 @@ 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(prefixed_name_template.begin(), prefixed_name_template.end());
70+
t.push_back('\0'); // add the zero
71+
const char *td = mkdtemp(t.data());
7072
if(!td)
7173
throw "mkdtemp failed";
7274
result=std::string(td);

0 commit comments

Comments
 (0)