Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop in SubprocessSet::DoWork() #2484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/subprocess-posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ bool SubprocessSet::DoWork() {
for (vector<Subprocess*>::iterator i = running_.begin();
i != running_.end(); ++i) {
Comment on lines 256 to 257
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way this one has the increment anyway

int fd = (*i)->fd_;
if (fd < 0)
continue;
pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
fds.push_back(pfd);
++nfds;
if (fd >= 0) {
pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
fds.push_back(pfd);
++nfds;
}
}

interrupted_ = 0;
Expand All @@ -281,18 +281,18 @@ bool SubprocessSet::DoWork() {
for (vector<Subprocess*>::iterator i = running_.begin();
i != running_.end(); ) {
int fd = (*i)->fd_;
if (fd < 0)
continue;
assert(fd == fds[cur_nfd].fd);
if (fds[cur_nfd++].revents) {
(*i)->OnPipeReady();
if ((*i)->Done()) {
finished_.push(*i);
i = running_.erase(i);
continue;
if (fd >= 0) {
assert(fd == fds[cur_nfd].fd);
if (fds[cur_nfd++].revents) {
(*i)->OnPipeReady();
}
}
++i;
if ((*i)->Done()) {
finished_.push(*i);
i = running_.erase(i);
} else {
++i;
}
}

return IsInterrupted();
Expand Down Expand Up @@ -333,13 +333,13 @@ bool SubprocessSet::DoWork() {
int fd = (*i)->fd_;
if (fd >= 0 && FD_ISSET(fd, &set)) {
(*i)->OnPipeReady();
Comment on lines 334 to 335
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is existing already, changes below have nothing to do with the fd value...

if an infinite loop is still possible after the fd value is handled then continue should cause increment of i, like how a normal for loop is written...

are we sure that omitting the increment in the loop itself isn't the actual mistake and all you need to do is put it back?

if ((*i)->Done()) {
finished_.push(*i);
i = running_.erase(i);
continue;
}
}
++i;
if ((*i)->Done()) {
finished_.push(*i);
i = running_.erase(i);
} else {
++i;
}
}

return IsInterrupted();
Expand Down
Loading