未验证 提交 d0be66cd 编写于 作者: J Jan Vorlicek 提交者: GitHub

Fix named mutex PAL test issue (#62655)

The issue seems to be caused by a bug in the test. The problematic call
to `TestCreateMutex` is passed `nullptr` as the `name` parameter. It
then calls `convert` helper on it to convert it to wide char. However,
the `convert` helper doesn't check whether it is `nullptr` or not and
ends up returning a pointer to a memory with possibly random data,
that is returned by `malloc(0)`. The returned pointer is then passed to
the CreateMutex PAL api that probably ends up attempting to get the
length of the name or something. And depending on the random data, it
sometimes fails.

The fix is to change the `convert` function to handle `nullptr` so that
it returns `nullptr` too.
上级 ba2072d6
......@@ -20,16 +20,19 @@ CRITICAL_SECTION CriticalSection;
WCHAR* convert(const char * aString)
{
int size;
WCHAR* wideBuffer;
WCHAR* wideBuffer = nullptr;
size = MultiByteToWideChar(CP_ACP,0,aString,-1,NULL,0);
wideBuffer = (WCHAR*) malloc(size*sizeof(WCHAR));
if (wideBuffer == NULL)
if (aString != nullptr)
{
Fail("ERROR: Unable to allocate memory!\n");
int size = MultiByteToWideChar(CP_ACP,0,aString,-1,NULL,0);
wideBuffer = (WCHAR*) malloc(size*sizeof(WCHAR));
if (wideBuffer == NULL)
{
Fail("ERROR: Unable to allocate memory!\n");
}
MultiByteToWideChar(CP_ACP,0,aString,-1,wideBuffer,size);
}
MultiByteToWideChar(CP_ACP,0,aString,-1,wideBuffer,size);
return wideBuffer;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册