Skip to content

Commit a78a1fe

Browse files
committed
Fix wsl image version status
1 parent 73ab06a commit a78a1fe

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

phlib/include/wslsup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ BOOLEAN PhInitializeLxssImageVersionInfo(
3333
_In_ PPH_STRING FileName
3434
);
3535

36-
ULONG PhCreateProcessLxss(
36+
_Success_(return)
37+
BOOLEAN PhCreateProcessLxss(
3738
_In_ PWSTR LxssDistribution,
3839
_In_ PWSTR LxssCommandLine,
3940
_In_opt_ PWSTR LxssCurrentDirectory,

phlib/wslsup.c

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ BOOLEAN PhInitializeLxssImageVersionInfo(
147147
_In_ PPH_STRING FileName
148148
)
149149
{
150-
ULONG status;
151150
PPH_STRING lxssCommandLine = NULL;
152151
PPH_STRING lxssPackageName = NULL;
153152
PPH_STRING lxssDistroName;
@@ -165,32 +164,29 @@ BOOLEAN PhInitializeLxssImageVersionInfo(
165164
return FALSE;
166165
}
167166

168-
if (PhIsNullOrEmptyString(lxssDistroName) || PhIsNullOrEmptyString(lxssDistroPath) || PhIsNullOrEmptyString(lxssFileName))
167+
if (
168+
PhIsNullOrEmptyString(lxssDistroName) ||
169+
PhIsNullOrEmptyString(lxssDistroPath) ||
170+
PhIsNullOrEmptyString(lxssFileName)
171+
)
169172
{
170173
if (lxssDistroName) PhDereferenceObject(lxssDistroName);
171174
if (lxssDistroPath) PhDereferenceObject(lxssDistroPath);
172175
if (lxssFileName) PhDereferenceObject(lxssFileName);
173176
return FALSE;
174177
}
175178

176-
if (PhEqualString2(lxssFileName, L"/init", FALSE))
177-
{
178-
PhMoveReference(&lxssFileName, PhCreateString(L"init"));
179-
}
180-
181179
PhMoveReference(&lxssCommandLine, PhFormatString(
182180
L"rpm -qf %s --queryformat \"%%{VERSION}|%%{VENDOR}|%%{SUMMARY}\"",
183181
lxssFileName->Buffer
184182
));
185183

186-
status = PhCreateProcessLxss(
184+
if (PhCreateProcessLxss(
187185
lxssDistroName->Buffer,
188186
lxssCommandLine->Buffer,
189187
NULL,
190188
&result
191-
);
192-
193-
if (status == 0)
189+
))
194190
{
195191
goto ParseResult;
196192
}
@@ -200,14 +196,12 @@ BOOLEAN PhInitializeLxssImageVersionInfo(
200196
lxssFileName->Buffer
201197
));
202198

203-
status = PhCreateProcessLxss(
199+
if (!PhCreateProcessLxss(
204200
lxssDistroName->Buffer,
205201
lxssCommandLine->Buffer,
206202
NULL,
207203
&result
208-
);
209-
210-
if (status != 0)
204+
))
211205
{
212206
PhDereferenceObject(lxssCommandLine);
213207
PhDereferenceObject(lxssDistroName);
@@ -242,14 +236,12 @@ BOOLEAN PhInitializeLxssImageVersionInfo(
242236
lxssPackageName->Buffer
243237
));
244238

245-
status = PhCreateProcessLxss(
239+
if (!PhCreateProcessLxss(
246240
lxssDistroName->Buffer,
247241
lxssCommandLine->Buffer,
248242
NULL,
249243
&result
250-
);
251-
252-
if (status != 0)
244+
))
253245
{
254246
PhDereferenceObject(lxssCommandLine);
255247
PhDereferenceObject(lxssDistroName);
@@ -293,7 +285,8 @@ BOOLEAN PhInitializeLxssImageVersionInfo(
293285
return TRUE;
294286
}
295287

296-
ULONG PhCreateProcessLxss(
288+
_Success_(return)
289+
BOOLEAN PhCreateProcessLxss(
297290
_In_ PWSTR LxssDistribution,
298291
_In_ PWSTR LxssCommandLine,
299292
_In_opt_ PWSTR LxssCurrentDirectory,
@@ -335,7 +328,7 @@ ULONG PhCreateProcessLxss(
335328
);
336329

337330
if (!NT_SUCCESS(status))
338-
return status;
331+
return FALSE;
339332

340333
status = PhCreatePipeEx(
341334
&inputReadHandle,
@@ -348,7 +341,7 @@ ULONG PhCreateProcessLxss(
348341
{
349342
NtClose(outputWriteHandle);
350343
NtClose(outputReadHandle);
351-
return status;
344+
return FALSE;
352345
}
353346

354347
memset(&startupInfo, 0, sizeof(STARTUPINFO));
@@ -378,7 +371,7 @@ ULONG PhCreateProcessLxss(
378371
NtClose(outputReadHandle);
379372
NtClose(inputReadHandle);
380373
NtClose(inputWriteHandle);
381-
return status;
374+
return FALSE;
382375
}
383376

384377
// Note: Close the write handles or the child process
@@ -396,18 +389,22 @@ ULONG PhCreateProcessLxss(
396389
}
397390

398391
// Note: Don't use NTSTATUS now that we have the lxss exit code. (dmex)
399-
if (Result && status == 0)
392+
if (status == 0)
400393
{
401-
*Result = lxssOutputString;
394+
if (Result) *Result = lxssOutputString;
395+
if (processHandle) NtClose(processHandle);
396+
if (outputReadHandle) NtClose(outputReadHandle);
397+
if (inputWriteHandle) NtClose(inputWriteHandle);
398+
399+
return TRUE;
402400
}
403401
else
404402
{
405-
PhSetReference(&lxssOutputString, NULL);
406-
}
403+
if (lxssOutputString) PhDereferenceObject(lxssOutputString);
404+
if (processHandle) NtClose(processHandle);
405+
if (outputReadHandle) NtClose(outputReadHandle);
406+
if (inputWriteHandle) NtClose(inputWriteHandle);
407407

408-
NtClose(processHandle);
409-
NtClose(outputReadHandle);
410-
NtClose(inputWriteHandle);
411-
412-
return status;
408+
return FALSE;
409+
}
413410
}

0 commit comments

Comments
 (0)