Skip to content

Commit 37d49e2

Browse files
committed
Use process ID and not random for uniqueness
Also fix some strcpy code for the command line
1 parent ca98119 commit 37d49e2

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/util/piped_process.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
3939
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa379560(v=vs.85) //NOLINT
4040
sec_attr.lpSecurityDescriptor = NULL;
4141
// Use named pipes to allow non-blocking read
42-
// Seed random numbers
43-
srand((unsigned)time(NULL));
4442
// Build the base name for the pipes
4543
std::string base_name = "\\\\.\\pipe\\cbmc\\SMT2\\child\\";
46-
// Use a random number here, a [G/U]UID would be better, but much more
47-
// annoying to handle on Windows and do the conversion.
48-
base_name.append(std::to_string(rand())); // NOLINT
44+
// Use process ID as a unique ID for this process at this time.
45+
base_name.append(std::to_string(GetCurrentProcessId()));
4946
std::string tmp_name = base_name;
5047
tmp_name.append("\\IN");
5148
LPCSTR tmp_str = tmp_name.c_str();
@@ -134,20 +131,17 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
134131
}
135132
// Note that we do NOT free this since it becomes part of the child
136133
// and causes heap corruption in Windows if we free!
137-
WCHAR *szCmdline =
138-
reinterpret_cast<WCHAR *>(malloc(sizeof(WCHAR) * cmdline.size()));
139-
wcscpy(szCmdline, cmdline.c_str());
140134
success = CreateProcessW(
141-
NULL, // application name, we only use the command below
142-
szCmdline, // command line
143-
NULL, // process security attributes
144-
NULL, // primary thread security attributes
145-
TRUE, // handles are inherited
146-
0, // creation flags
147-
NULL, // use parent's environment
148-
NULL, // use parent's current directory
149-
&start_info, // STARTUPINFO pointer
150-
&proc_info); // receives PROCESS_INFORMATION
135+
NULL, // application name, we only use the command below
136+
_wcsdup(cmdline.c_str()), // command line
137+
NULL, // process security attributes
138+
NULL, // primary thread security attributes
139+
TRUE, // handles are inherited
140+
0, // creation flags
141+
NULL, // use parent's environment
142+
NULL, // use parent's current directory
143+
&start_info, // STARTUPINFO pointer
144+
&proc_info); // receives PROCESS_INFORMATION
151145
// Close handles to the stdin and stdout pipes no longer needed by the
152146
// child process. If they are not explicitly closed, there is no way to
153147
// recognize that the child process has ended (but maybe we don't care).

0 commit comments

Comments
 (0)