@@ -45,20 +45,18 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context)
45
45
HRESULT hr;
46
46
UUID uuid;
47
47
RPC_CSTR suuid = NULL ;
48
- LPTSTR fullCommandLine = NULL ;
49
- LPCTSTR coreCommandLine;
50
- LPCTSTR interceptor;
48
+ LPWSTR fullCommandLine = NULL ;
49
+ LPCWSTR coreCommandLine;
50
+ LPCWSTR interceptor;
51
51
PCWSTR scriptName;
52
- size_t coreCommandLineLength, scriptNameLength, scriptNameLengthW, interceptorLength;
53
52
PROCESS_INFORMATION processInformation;
54
53
DWORD exitCode = S_OK;
55
54
LPCH newEnvironment = NULL ;
56
55
DWORD flags;
57
56
HANDLE job;
58
57
PWSTR currentDirectory = NULL ;
59
- PSTR currentDirectoryA = NULL ;
58
+ PWSTR scriptTranslated = NULL ;
60
59
DWORD currentDirectorySize = 0 ;
61
- DWORD currentDirectorySizeA = 0 ;
62
60
CNodeApplication* app = this ->GetProcessManager ()->GetApplication ();
63
61
64
62
RtlZeroMemory (&processInformation, sizeof processInformation);
@@ -80,53 +78,44 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context)
80
78
// build the full command line for the node.js process
81
79
82
80
interceptor = CModuleConfiguration::GetInterceptor (context);
83
- interceptorLength = strlen (interceptor);
84
81
coreCommandLine = CModuleConfiguration::GetNodeProcessCommandLine (context);
85
82
scriptName = this ->GetProcessManager ()->GetApplication ()->GetScriptName ();
86
- coreCommandLineLength = _tcslen (coreCommandLine);
87
- scriptNameLengthW = wcslen (scriptName) + 1 ;
88
- ErrorIf (0 != wcstombs_s (&scriptNameLength, NULL , 0 , scriptName, _TRUNCATE), ERROR_CAN_NOT_COMPLETE);
89
83
// allocate memory for command line to allow for debugging options plus interceptor plus spaces and enclosing the script name in quotes
90
- ErrorIf (NULL == (fullCommandLine = new TCHAR[coreCommandLineLength + interceptorLength + scriptNameLength + 256 ]), ERROR_NOT_ENOUGH_MEMORY);
91
- _tcscpy (fullCommandLine, coreCommandLine);
92
- DWORD offset = 0 ;
84
+ ErrorIf (NULL == (fullCommandLine = new WCHAR[wcslen (coreCommandLine) + wcslen (interceptor) + wcslen (scriptName) + 256 ]), ERROR_NOT_ENOUGH_MEMORY);
85
+ wcscpy (fullCommandLine, coreCommandLine);
93
86
94
87
// add debug options
95
88
if (app->IsDebuggee ())
96
89
{
97
- char buffer[64 ];
90
+ WCHAR buffer[64 ];
98
91
99
92
if (ND_DEBUG_BRK == app->GetDebugCommand ())
100
93
{
101
- sprintf (buffer, " --debug-brk=%d " , app->GetDebugPort ());
94
+ swprintf (buffer, L " --debug-brk=%d " , app->GetDebugPort ());
102
95
}
103
96
else if (ND_DEBUG == app->GetDebugCommand ())
104
97
{
105
- sprintf (buffer, " --debug=%d " , app->GetDebugPort ());
98
+ swprintf (buffer, L " --debug=%d " , app->GetDebugPort ());
106
99
}
107
100
else
108
101
{
109
102
CheckError (ERROR_INVALID_PARAMETER);
110
103
}
111
104
112
- _tcscat (fullCommandLine, buffer);
113
- offset += strlen (buffer);
105
+ wcscat (fullCommandLine, buffer);
114
106
}
115
107
116
108
if (!app->IsDebugger ())
117
109
{
118
110
// add interceptor
119
- _tcscat (fullCommandLine, _T (" " ));
120
- offset += 1 ;
121
- _tcscat (fullCommandLine, interceptor);
122
- offset += interceptorLength;
111
+ wcscat (fullCommandLine, L" " );
112
+ wcscat (fullCommandLine, interceptor);
123
113
}
124
114
125
115
// add application entry point
126
- _tcscat (fullCommandLine, _T (" \" " ));
127
- offset += 2 ;
128
- ErrorIf (0 != wcstombs_s (&scriptNameLength, fullCommandLine + coreCommandLineLength + offset, scriptNameLength, scriptName, _TRUNCATE), ERROR_CAN_NOT_COMPLETE);
129
- _tcscat (fullCommandLine, _T (" \" " ));
116
+ wcscat (fullCommandLine, L" \" " );
117
+ wcscat (fullCommandLine, scriptName);
118
+ wcscat (fullCommandLine, L" \" " );
130
119
131
120
// create the environment block for the node.js process
132
121
@@ -139,18 +128,17 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context)
139
128
// establish the current directory for node.exe process to be the same as the location of the application *.js file
140
129
// (in case of the debugger process, it is still the debuggee application file)
141
130
142
- currentDirectory = (PWSTR)context->GetScriptTranslated (¤tDirectorySize);
143
- while (currentDirectorySize && currentDirectory [currentDirectorySize] != L' \\ ' && currentDirectory [currentDirectorySize] != L' /' )
131
+ scriptTranslated = (PWSTR)context->GetScriptTranslated (¤tDirectorySize);
132
+ while (currentDirectorySize && scriptTranslated [currentDirectorySize] != L' \\ ' && scriptTranslated [currentDirectorySize] != L' /' )
144
133
currentDirectorySize--;
145
- ErrorIf (0 == (currentDirectorySizeA = WideCharToMultiByte (CP_ACP, 0 , currentDirectory, currentDirectorySize, NULL , 0 , NULL , NULL )), E_FAIL);
146
- ErrorIf (NULL == (currentDirectoryA = new char [currentDirectorySize + 1 ]), ERROR_NOT_ENOUGH_MEMORY);
147
- ErrorIf (currentDirectorySizeA != WideCharToMultiByte (CP_ACP, 0 , currentDirectory, currentDirectorySize, currentDirectoryA, currentDirectorySizeA, NULL , NULL ), E_FAIL);
148
- currentDirectoryA[currentDirectorySizeA] = ' \0 ' ;
134
+ ErrorIf (NULL == (currentDirectory = new WCHAR[wcslen (scriptTranslated) + 1 ]), ERROR_NOT_ENOUGH_MEMORY);
135
+ wcscpy (currentDirectory, scriptTranslated);
136
+ currentDirectory[currentDirectorySize] = L' \0 ' ;
149
137
150
138
// create startup info for the node.js process
151
139
152
140
RtlZeroMemory (&this ->startupInfo , sizeof this ->startupInfo );
153
- GetStartupInfo (&startupInfo);
141
+ GetStartupInfoW (&startupInfo);
154
142
CheckError (this ->CreateStdHandles (context));
155
143
156
144
// create process watcher thread in a suspended state
@@ -172,15 +160,15 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context)
172
160
flags |= CREATE_BREAKAWAY_FROM_JOB;
173
161
}
174
162
175
- if (!CreateProcess (
163
+ if (!CreateProcessW (
176
164
NULL ,
177
165
fullCommandLine,
178
166
NULL ,
179
167
NULL ,
180
168
TRUE ,
181
169
flags,
182
170
newEnvironment,
183
- currentDirectoryA ,
171
+ currentDirectory ,
184
172
&this ->startupInfo ,
185
173
&processInformation))
186
174
{
@@ -211,8 +199,8 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context)
211
199
212
200
// clean up
213
201
214
- delete [] currentDirectoryA ;
215
- currentDirectoryA = NULL ;
202
+ delete [] currentDirectory ;
203
+ currentDirectory = NULL ;
216
204
delete [] newEnvironment;
217
205
newEnvironment = NULL ;
218
206
delete [] fullCommandLine;
@@ -245,10 +233,10 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context)
245
233
L" iisnode failed to initialize a new node.exe process" , WINEVENT_LEVEL_ERROR);
246
234
}
247
235
248
- if (currentDirectoryA )
236
+ if (currentDirectory )
249
237
{
250
- delete [] currentDirectoryA ;
251
- currentDirectoryA = NULL ;
238
+ delete [] currentDirectory ;
239
+ currentDirectory = NULL ;
252
240
}
253
241
254
242
if (suuid != NULL )
0 commit comments