mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-14 13:00:41 +02:00
FEXServer: Fix unsafe vector insert/removal
Depending on the operation we will do a vector insert or removal while iterating over the vector. Fixes a use after free that asan found when insert caused the vector to resize.
This commit is contained in:
1 parent
9664d98ba5
commit
b45f27c8d0
1 file changed
+7
-2
@@ -434,6 +434,8 @@ namespace ProcessPipe {
|
||||
ts.tv_sec = RequestTimeout;
|
||||
|
||||
int Result = ppoll(&PollFDs.at(0), PollFDs.size(), &ts, nullptr);
|
||||
std::vector<struct pollfd> NewPollFDs{};
|
||||
|
||||
if (Result > 0) {
|
||||
// Walk the FDs and see if we got any results
|
||||
for (auto it = PollFDs.begin(); it != PollFDs.end(); ) {
|
||||
@@ -448,8 +450,8 @@ namespace ProcessPipe {
|
||||
socklen_t AddrSize{};
|
||||
int NewFD = accept(ServerSocketFD, reinterpret_cast<struct sockaddr*>(&Addr), &AddrSize);
|
||||
|
||||
// Add the new client to the array
|
||||
PollFDs.emplace_back(pollfd {
|
||||
// Add the new client to the temporary array
|
||||
NewPollFDs.emplace_back(pollfd {
|
||||
.fd = NewFD,
|
||||
.events = POLLIN | POLLPRI | POLLRDHUP | POLLREMOVE,
|
||||
.revents = 0,
|
||||
@@ -490,6 +492,9 @@ namespace ProcessPipe {
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the new FDs to poll
|
||||
PollFDs.insert(PollFDs.begin(), NewPollFDs.begin(), NewPollFDs.end());
|
||||
|
||||
LastDataTime = std::chrono::system_clock::now();
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in new issue
Block a user