Skip to content

Commit

Permalink
Fix segfault in cmd_filter
Browse files Browse the repository at this point in the history
Using FD_ISSET on negative file descriptors results in breakage.

Closes martanne#55.
  • Loading branch information
martanne committed Jun 30, 2015
1 parent 4af9fe6 commit 860ad58
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ static bool cmd_filter(Filerange *range, enum CmdOpt opt, const char *argv[]) {
break;
}

if (FD_ISSET(pin[1], &wfds)) {
if (pin[1] != -1 && FD_ISSET(pin[1], &wfds)) {
Filerange junk = *range;
if (junk.end > junk.start + PIPE_BUF)
junk.end = junk.start + PIPE_BUF;
Expand All @@ -1798,7 +1798,7 @@ static bool cmd_filter(Filerange *range, enum CmdOpt opt, const char *argv[]) {
}
}

if (FD_ISSET(pout[0], &rfds)) {
if (pout[0] != -1 && FD_ISSET(pout[0], &rfds)) {
char buf[BUFSIZ];
ssize_t len = read(pout[0], buf, sizeof buf);
if (len > 0) {
Expand All @@ -1814,7 +1814,7 @@ static bool cmd_filter(Filerange *range, enum CmdOpt opt, const char *argv[]) {
}
}

if (FD_ISSET(perr[0], &rfds)) {
if (perr[0] != -1 && FD_ISSET(perr[0], &rfds)) {
char buf[BUFSIZ];
ssize_t len = read(perr[0], buf, sizeof buf);
if (len > 0) {
Expand Down

0 comments on commit 860ad58

Please sign in to comment.