[coverity] 1543227 Readlink used insecurely

This commit is contained in:
akallabeth 2024-04-11 10:43:14 +02:00 committed by akallabeth
parent 3b04ab95d4
commit 3997eeb5b3

View File

@ -274,18 +274,17 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
if (!hModule)
{
char buffer[4096];
char buffer[4096] = { 0 };
sprintf_s(path, ARRAYSIZE(path), "/proc/%d/exe", getpid());
status = readlink(path, buffer, sizeof(buffer));
status = readlink(path, buffer, ARRAYSIZE(buffer) - 1);
if (status < 0)
if ((status < 0) || (status >= ARRAYSIZE(buffer)))
{
SetLastError(ERROR_INTERNAL_ERROR);
return 0;
}
buffer[status] = '\0';
length = strnlen(buffer, sizeof(buffer));
length = strnlen(buffer, ARRAYSIZE(buffer));
if (length < nSize)
{