@@ -39,13 +39,10 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
39
39
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa379560(v=vs.85) //NOLINT
40
40
sec_attr.lpSecurityDescriptor = NULL ;
41
41
// Use named pipes to allow non-blocking read
42
- // Seed random numbers
43
- srand ((unsigned )time (NULL ));
44
42
// Build the base name for the pipes
45
43
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 ()));
49
46
std::string tmp_name = base_name;
50
47
tmp_name.append (" \\ IN" );
51
48
LPCSTR tmp_str = tmp_name.c_str ();
@@ -134,20 +131,17 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
134
131
}
135
132
// Note that we do NOT free this since it becomes part of the child
136
133
// 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 ());
140
134
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
151
145
// Close handles to the stdin and stdout pipes no longer needed by the
152
146
// child process. If they are not explicitly closed, there is no way to
153
147
// recognize that the child process has ended (but maybe we don't care).
0 commit comments