[CMD] Add missing memory allocation NULL checks (#161). CORE-8304

Adapted from a patch by Jacob S. Preciado.

Bring also the code suggestions emitted during review.
This commit is contained in:
Hermès Bélusca-Maïto
2017-12-03 18:49:41 +01:00
parent 73798d2e71
commit 3f892a8d6b
16 changed files with 293 additions and 147 deletions

View File

@@ -50,6 +50,12 @@ INT cmd_path (LPTSTR param)
LPTSTR pszBuffer;
pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
if (!pszBuffer)
{
WARN("Cannot allocate memory for pszBuffer!\n");
return 1;
}
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
if (dwBuffer == 0)
{
@@ -61,8 +67,9 @@ INT cmd_path (LPTSTR param)
{
LPTSTR pszOldBuffer = pszBuffer;
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
if (pszBuffer == NULL)
if (!pszBuffer)
{
WARN("Cannot reallocate memory for pszBuffer!\n");
cmd_free(pszOldBuffer);
return 1;
}