Skip to content

Instantly share code, notes, and snippets.

@historicbruno
Created September 4, 2014 18:26
Show Gist options
  • Save historicbruno/8a2b790a381a16c795e1 to your computer and use it in GitHub Desktop.
Save historicbruno/8a2b790a381a16c795e1 to your computer and use it in GitHub Desktop.
CheckEventLog: incorrect error handling for failed EvtQuery
diff --git a/modules/CheckEventLog/CheckEventLog.cpp b/modules/CheckEventLog/CheckEventLog.cpp
index 900361d..e2d764e 100644
--- a/modules/CheckEventLog/CheckEventLog.cpp
+++ b/modules/CheckEventLog/CheckEventLog.cpp
@@ -262,15 +262,15 @@ void check_modern(const std::string &logfile, const std::string &scan_range, con
}
eventlog::evt_handle hResults = eventlog::EvtQuery(NULL, utf8::cvt<std::wstring>(logfile).c_str(), pwsQuery, flags);
if (!hResults)
- throw nscp_exception("Failed to open channel: " + error::lookup::last_error(status));
- status = GetLastError();
- if (status == ERROR_EVT_CHANNEL_NOT_FOUND)
- throw nscp_exception("Channel not found: " + error::lookup::last_error(status));
- else if (status == ERROR_EVT_INVALID_QUERY)
- throw nscp_exception("Invalid query: " + error::lookup::last_error(status));
- else if (status != ERROR_SUCCESS)
- throw nscp_exception("EvtQuery failed: " + error::lookup::last_error(status));
-
+ {
+ status = GetLastError();
+ if (status == ERROR_EVT_CHANNEL_NOT_FOUND)
+ throw nscp_exception("Channel not found: " + error::lookup::last_error(status));
+ else if (status == ERROR_EVT_INVALID_QUERY)
+ throw nscp_exception("Invalid query: " + error::lookup::last_error(status));
+ else if (status != ERROR_SUCCESS)
+ throw nscp_exception("EvtQuery failed: " + error::lookup::last_error(status));
+ }
eventlog::evt_handle hContext = eventlog::EvtCreateRenderContext(0, NULL, eventlog::api::EvtRenderContextSystem);
if (!hContext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment