Author: weiden
Date: Sun Feb 4 19:06:08 2007
New Revision: 25712
URL:
http://svn.reactos.org/svn/reactos?rev=25712&view=rev
Log:
Fix the code to read the SystemDrive environment variable
Modified:
trunk/reactos/dll/cpl/sysdm/startrec.c
Modified: trunk/reactos/dll/cpl/sysdm/startrec.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/sysdm/startrec.c?r…
==============================================================================
--- trunk/reactos/dll/cpl/sysdm/startrec.c (original)
+++ trunk/reactos/dll/cpl/sysdm/startrec.c Sun Feb 4 19:06:08 2007
@@ -45,22 +45,49 @@
{
case WM_INITDIALOG:
{
+ DWORD dwBufSize;
+
/* get Path to freeldr.ini or boot.ini */
- szSystemDrive = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PATH);
+ szSystemDrive = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(TCHAR));
if (szSystemDrive != NULL)
{
- szSystemDrive = _tgetenv(_T("SystemDrive"));
- if (m_szFreeldrIni != NULL && szSystemDrive != NULL)
- {
- _tcscpy(m_szFreeldrIni, szSystemDrive);
- _tcscat(m_szFreeldrIni, _T("\\freeldr.ini"));
- if (!PathFileExists(m_szFreeldrIni))
+ dwBufSize = GetEnvironmentVariable(_T("SystemDrive"), szSystemDrive,
MAX_PATH);
+ if (dwBufSize > MAX_PATH)
+ {
+ TCHAR *szTmp;
+ DWORD dwBufSize2;
+
+ szTmp = HeapReAlloc(GetProcessHeap(), 0, szSystemDrive, dwBufSize * sizeof(TCHAR));
+ if (szTmp == NULL)
+ goto FailGetSysDrive;
+
+ szSystemDrive = szTmp;
+
+ dwBufSize2 = GetEnvironmentVariable(_T("SystemDrive"), szSystemDrive,
dwBufSize);
+ if (dwBufSize2 > dwBufSize || dwBufSize2 == 0)
+ goto FailGetSysDrive;
+ }
+ else if (dwBufSize == 0)
+ {
+FailGetSysDrive:
+ HeapFree(GetProcessHeap(), 0, szSystemDrive);
+ szSystemDrive = NULL;
+ }
+
+ if (szSystemDrive != NULL)
+ {
+ if (m_szFreeldrIni != NULL)
{
_tcscpy(m_szFreeldrIni, szSystemDrive);
- _tcscat(m_szFreeldrIni, _T("\\boot.ini"));
+ _tcscat(m_szFreeldrIni, _T("\\freeldr.ini"));
+ if (!PathFileExists(m_szFreeldrIni))
+ {
+ _tcscpy(m_szFreeldrIni, szSystemDrive);
+ _tcscat(m_szFreeldrIni, _T("\\boot.ini"));
+ }
}
+ HeapFree(GetProcessHeap(), 0, szSystemDrive);
}
- HeapFree(GetProcessHeap(), 0, szSystemDrive);
}
SetDlgItemText(hwndDlg, IDC_STRRECDUMPFILE, _T("%SystemRoot%\\MiniDump"));