On 2016-06-28 21:21, hbelusca(a)svn.reactos.org wrote:
---
trunk/reactos/base/system/subst/subst.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/subst/subst.c [iso-8859-1] Tue Jun 28 19:21:08 2016
@@ -75,81 +75,71 @@
if (_tcslen(Drive) > 2)
return FALSE;
- dwSize = sizeof(TCHAR) * MAX_PATH;
- lpTargetPath = (LPTSTR) malloc(sizeof(TCHAR) * MAX_PATH);
- if ( lpTargetPath)
- {
+ dwSize = MAX_PATH;
+ lpTargetPath = (LPTSTR)malloc(sizeof(TCHAR) * dwSize);
+ if (!lpTargetPath)
+ return FALSE;
+
+ CharCount = QueryDosDevice(Drive,
+ lpTargetPath,
+ dwSize);
+ while (!CharCount &&
+ GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+ {
+ lpTargetPath = (LPTSTR)realloc(lpTargetPath, sizeof(TCHAR) * dwSize);
This is not how you use realloc, this causes a memory leak in case of
failure.
Also, why is there a cast here (also, for malloc above)?
Thanks.
-Thomas
+ if (lpTargetPath)
+ {
+ CharCount = QueryDosDevice(Drive,
+ lpTargetPath,
+ dwSize);
+ }
+ }
+
+ if (CharCount)
+ {
+ Result = _tcsncmp(lpTargetPath, _T("\\??\\"), 4) == 0 &&
+ ( (lpTargetPath[4] >= _T('A') &&
+ lpTargetPath[4] <= _T('Z')) ||
+ (lpTargetPath[4] >= _T('a') &&
+ lpTargetPath[4] <= _T('z')) );
+ }
+
+ free(lpTargetPath);
+
+ return Result;
+}