https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bb03da981cf476686b05884bdcef3f507f3b88f8

commit bb03da981cf476686b05884bdcef3f507f3b88f8
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Fri Apr 13 00:52:25 2018 +0200
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Fri Apr 13 01:02:20 2018 +0200

    [EVENTVWR] Additions to the Event Viewer.
    
    - Don't hardcode a buffer length in ExpandEnvironmentStringsW() call.
    - If no file name is associated to a log (ErrorLog->FileName == NULL),
      don't try to attempt looking at its file properties. This also allows
      avoiding a crash in the FindFirstFileW() call under certain conditions
      on Windows.
---
 base/applications/mscutils/eventvwr/eventvwr.c | 44 ++++++++++++++++----------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/base/applications/mscutils/eventvwr/eventvwr.c 
b/base/applications/mscutils/eventvwr/eventvwr.c
index 6801b275e4..f7e89d3207 100644
--- a/base/applications/mscutils/eventvwr/eventvwr.c
+++ b/base/applications/mscutils/eventvwr/eventvwr.c
@@ -3459,30 +3459,40 @@ Quit:
     FileName = EventLog->FileName;
     if (FileName && *FileName)
     {
-        ExpandEnvironmentStringsW(FileName, wszBuf, MAX_PATH);
+        ExpandEnvironmentStringsW(FileName, wszBuf, ARRAYSIZE(wszBuf));
         FileName = wszBuf;
     }
+    else
+    {
+        FileName = L"";
+    }
     SetDlgItemTextW(hDlg, IDC_LOGFILE, FileName);
 
-    /*
-     * The general problem here (and in the shell as well) is that
-     * GetFileAttributesEx fails for files that are opened without
-     * shared access. To retrieve file information for those we need
-     * to use something else: FindFirstFile, on the full file name.
-     */
-
-    Success = GetFileAttributesExW(FileName,
-                                   GetFileExInfoStandard,
-                                   (LPWIN32_FILE_ATTRIBUTE_DATA)&FileInfo);
-    if (!Success)
+    if (FileName && *FileName)
+    {
+        /*
+         * The general problem here (and in the shell as well) is that
+         * GetFileAttributesEx fails for files that are opened without
+         * shared access. To retrieve file information for those we need
+         * to use something else: FindFirstFile, on the full file name.
+         */
+        Success = GetFileAttributesExW(FileName,
+                                       GetFileExInfoStandard,
+                                       (LPWIN32_FILE_ATTRIBUTE_DATA)&FileInfo);
+        if (!Success)
+        {
+            HANDLE hFind = FindFirstFileW(FileName, &FileInfo);
+            Success = (hFind != INVALID_HANDLE_VALUE);
+            if (Success)
+                FindClose(hFind);
+        }
+    }
+    else
     {
-        HANDLE hFind = FindFirstFileW(FileName, &FileInfo);
-        Success = (hFind != INVALID_HANDLE_VALUE);
-        if (Success)
-            FindClose(hFind);
+        Success = FALSE;
     }
 
-    // Starting there, FileName is invalid (because it uses wszBuf)
+    /* Starting there, FileName becomes invalid because we are reusing wszBuf 
*/
 
     if (Success)
     {

Reply via email to