Skip to content

Commit a6da182

Browse files
dendyDaniel Levin
authored and
Daniel Levin
committed
Fix infinite loop in SubprocessSet::DoWork()
In case fd is invalid loop will be infinite because iterator is not incremented. Make loop consistent between both variants of SubprocessSet::DoWork() (with and withoug USE_PPOLL) by removing 'continue' and always advancing iterator in the end of the cycle.
1 parent f220dc5 commit a6da182

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/subprocess-posix.cc

+21-21
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ bool SubprocessSet::DoWork() {
256256
for (vector<Subprocess*>::iterator i = running_.begin();
257257
i != running_.end(); ++i) {
258258
int fd = (*i)->fd_;
259-
if (fd < 0)
260-
continue;
261-
pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
262-
fds.push_back(pfd);
263-
++nfds;
259+
if (fd >= 0) {
260+
pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
261+
fds.push_back(pfd);
262+
++nfds;
263+
}
264264
}
265265

266266
interrupted_ = 0;
@@ -281,18 +281,18 @@ bool SubprocessSet::DoWork() {
281281
for (vector<Subprocess*>::iterator i = running_.begin();
282282
i != running_.end(); ) {
283283
int fd = (*i)->fd_;
284-
if (fd < 0)
285-
continue;
286-
assert(fd == fds[cur_nfd].fd);
287-
if (fds[cur_nfd++].revents) {
288-
(*i)->OnPipeReady();
289-
if ((*i)->Done()) {
290-
finished_.push(*i);
291-
i = running_.erase(i);
292-
continue;
284+
if (fd >= 0) {
285+
assert(fd == fds[cur_nfd].fd);
286+
if (fds[cur_nfd++].revents) {
287+
(*i)->OnPipeReady();
293288
}
294289
}
295-
++i;
290+
if ((*i)->Done()) {
291+
finished_.push(*i);
292+
i = running_.erase(i);
293+
} else {
294+
++i;
295+
}
296296
}
297297

298298
return IsInterrupted();
@@ -333,13 +333,13 @@ bool SubprocessSet::DoWork() {
333333
int fd = (*i)->fd_;
334334
if (fd >= 0 && FD_ISSET(fd, &set)) {
335335
(*i)->OnPipeReady();
336-
if ((*i)->Done()) {
337-
finished_.push(*i);
338-
i = running_.erase(i);
339-
continue;
340-
}
341336
}
342-
++i;
337+
if ((*i)->Done()) {
338+
finished_.push(*i);
339+
i = running_.erase(i);
340+
} else {
341+
++i;
342+
}
343343
}
344344

345345
return IsInterrupted();

0 commit comments

Comments
 (0)