Fix rare corner case in ntspawn.c

There could be cases when libc/proc/describefds.c calls calloc(handlecount, ..) with handlecount = 0 to initialize 
what will later become opt_lpExplicitHandleList.
but calloc(0, ..) does not always return null so if the chosen conditional is a->opt_lpExplicitHandleList then UpdateProcThreadAttribute produces a Windows error.
The modification avoids this problem.
This commit is contained in:
jeromew 2024-09-08 12:18:56 +02:00 committed by GitHub
parent 4754f200ee
commit 823a89d3ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -166,7 +166,7 @@ static textwindows int ntspawn2(struct NtSpawnArgs *a, struct SpawnBlock *sb) {
alist, 0, kNtProcThreadAttributeParentProcess, &a->opt_hParentProcess,
sizeof(a->opt_hParentProcess), 0, 0);
}
if (ok && a->opt_lpExplicitHandleList) {
if (ok && a->dwExplicitHandleCount) {
ok = UpdateProcThreadAttribute(
alist, 0, kNtProcThreadAttributeHandleList, a->opt_lpExplicitHandleList,
a->dwExplicitHandleCount * sizeof(*a->opt_lpExplicitHandleList), 0, 0);