catch garbage pipe data

This commit is contained in:
Akash Mozumdar 2019-06-09 07:33:26 -04:00
parent 121606af14
commit d25a61e9e6
5 changed files with 6 additions and 5 deletions

View File

@ -134,11 +134,12 @@ namespace
{
auto tp = *(ThreadParam*)buffer;
auto textThreadsByParams = ::textThreadsByParams.Acquire();
if (textThreadsByParams->count(tp) == 0)
if (textThreadsByParams->count(tp) == 0) try
{
TextThread& created = textThreadsByParams->try_emplace(tp, tp, Host::GetHookParam(tp)).first->second;
OnCreate(created);
}
catch (std::out_of_range) { continue; } // probably garbage data in pipe, try again
textThreadsByParams->find(tp)->second.Push(buffer + sizeof(tp), bytesRead - sizeof(tp));
}
break;

View File

@ -375,7 +375,7 @@ void MainWindow::FindHooks()
QByteArray pattern = QByteArray::fromHex(patternInput->text().replace("??", "11").toUtf8());
if (pattern.size() < 3) return;
std::wregex filter(L".");
if (!filterInput->text().isEmpty()) try { filter = std::wregex(S(filterInput->text())); } catch (std::regex_error&) {};
if (!filterInput->text().isEmpty()) try { filter = std::wregex(S(filterInput->text())); } catch (std::regex_error) {};
memcpy(sp.pattern, pattern.data(), sp.length = min(pattern.size(), 25));
auto hooks = std::make_shared<QString>();
Host::FindHooks(processId, sp, [hooks, filter](HookParam hp, DWORD processId, const std::wstring& text)

View File

@ -18,7 +18,7 @@ struct : QMainWindow
{
std::lock_guard l(m);
try { regex = newRegex.toStdWString(); }
catch (...) { return ui.output->setText(INVALID_REGEX); }
catch (std::regex_error) { return ui.output->setText(INVALID_REGEX); }
ui.output->setText(QString(CURRENT_FILTER).arg(newRegex));
});
setWindowTitle(REGEX_FILTER);

View File

@ -74,7 +74,7 @@ private:
std::unique_ptr<void, HandleCleaner> h;
};
inline struct
static struct
{
BYTE DUMMY[100];
template <typename T>

View File

@ -160,7 +160,7 @@ void SearchForHooks(SearchParam sp)
std::scoped_lock lock(m);
try { records = std::make_unique<HookRecord[]>(recordsAvailable = CACHE_SIZE); }
catch (std::bad_alloc&) { return ConsoleOutput("Textractor: SearchForHooks ERROR (out of memory)"); }
catch (std::bad_alloc) { return ConsoleOutput("Textractor: SearchForHooks ERROR (out of memory)"); }
current = sp;