From 90d3b9a3131ac7094e4bfbf0330769c546560651 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Thu, 29 Jul 2021 11:08:19 +0300 Subject: [PATCH] kernelbase: Don't allow converting thread to fiber more than once. Signed-off-by: Paul Gofman Signed-off-by: Alexandre Julliard --- dlls/kernel32/tests/fiber.c | 14 ++++++++++++++ dlls/kernelbase/thread.c | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/dlls/kernel32/tests/fiber.c b/dlls/kernel32/tests/fiber.c index 3c54351fa7b..9ae45c2091b 100644 --- a/dlls/kernel32/tests/fiber.c +++ b/dlls/kernel32/tests/fiber.c @@ -128,10 +128,17 @@ static VOID WINAPI FiberMainProc(LPVOID lpFiberParameter) static void test_ConvertThreadToFiber(void) { + void *ret; + if (pConvertThreadToFiber) { fibers[0] = pConvertThreadToFiber(&testparam); ok(fibers[0] != NULL, "ConvertThreadToFiber failed with error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = pConvertThreadToFiber(&testparam); + ok(!ret, "Got non NULL ret.\n"); + ok(GetLastError() == ERROR_ALREADY_FIBER, "Got unexpected error %u.\n", GetLastError()); } else { @@ -141,10 +148,17 @@ static void test_ConvertThreadToFiber(void) static void test_ConvertThreadToFiberEx(void) { + void *ret; + if (pConvertThreadToFiberEx) { fibers[0] = pConvertThreadToFiberEx(&testparam, 0); ok(fibers[0] != NULL, "ConvertThreadToFiberEx failed with error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = pConvertThreadToFiberEx(&testparam, 0); + ok(!ret, "Got non NULL ret.\n"); + ok(GetLastError() == ERROR_ALREADY_FIBER, "Got unexpected error %u.\n", GetLastError()); } else { diff --git a/dlls/kernelbase/thread.c b/dlls/kernelbase/thread.c index 61cb74c6222..9b97c4a8914 100644 --- a/dlls/kernelbase/thread.c +++ b/dlls/kernelbase/thread.c @@ -990,6 +990,12 @@ LPVOID WINAPI DECLSPEC_HOTPATCH ConvertThreadToFiberEx( LPVOID param, DWORD flag { struct fiber_data *fiber; + if (NtCurrentTeb()->Tib.u.FiberData) + { + SetLastError( ERROR_ALREADY_FIBER ); + return NULL; + } + if (!(fiber = HeapAlloc( GetProcessHeap(), 0, sizeof(*fiber) ))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY );