Skip to content

Commit 965df2f

Browse files
committed
[CMD]: Check for cmd_realloc returned value. Adapted from patch by Patrick Martin, see CORE-7298.
svn path=/trunk/; revision=67065
1 parent a18fba6 commit 965df2f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

reactos/base/shell/cmd/path.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ INT cmd_path (LPTSTR param)
5959
}
6060
else if (dwBuffer > ENV_BUFFER_SIZE)
6161
{
62+
LPTSTR pszOldBuffer = pszBuffer;
6263
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
64+
if (pszBuffer == NULL)
65+
{
66+
cmd_free(pszOldBuffer);
67+
return 1;
68+
}
6369
GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer);
6470
}
6571

reactos/base/shell/cmd/where.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
152152
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
153153
if (dwBuffer > ENV_BUFFER_SIZE)
154154
{
155+
LPTSTR pszOldPathExt = pszPathExt;
155156
pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
157+
if (pszPathExt == NULL)
158+
{
159+
cmd_free(pszOldPathExt);
160+
return FALSE;
161+
}
156162
GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, dwBuffer);
157163
_tcslwr(pszPathExt);
158164
}
@@ -184,7 +190,14 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
184190
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
185191
if (dwBuffer > ENV_BUFFER_SIZE)
186192
{
193+
LPTSTR pszOldPath = pszPath;
187194
pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
195+
if (pszPath == NULL)
196+
{
197+
cmd_free(pszOldPath);
198+
cmd_free(pszPathExt);
199+
return FALSE;
200+
}
188201
GetEnvironmentVariable (_T("PATH"), pszPath, dwBuffer);
189202
}
190203

0 commit comments

Comments
 (0)