2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 14:25:15 +00:00

Reinstall the event handler if we get EAGAIN from read/write callback.

The read and write events do not set SUDO_EV_PERSIST so we need to
explicitly re-enable the event if there is still data to be read.
Bug #963.
This commit is contained in:
Todd C. Miller
2022-06-06 19:42:07 -06:00
parent db6fc237c4
commit c2a131714a

View File

@@ -676,8 +676,12 @@ read_callback(int fd, int what, void *v)
/* Schedule SIGTTIN to be forwarded to the command. */
schedule_signal(iob->ec, SIGTTIN);
}
if (errno == EAGAIN || errno == EINTR)
if (errno == EAGAIN || errno == EINTR) {
/* Re-enable reader. */
if (sudo_ev_add(evbase, iob->revent, NULL, false) == -1)
sudo_fatal("%s", U_("unable to add event to queue"));
break;
}
/* treat read error as fatal and close the fd */
sudo_debug_printf(SUDO_DEBUG_ERROR,
"error reading fd %d: %s", fd, strerror(errno));
@@ -717,6 +721,8 @@ read_callback(int fd, int what, void *v)
}
break;
}
debug_return;
}
/*
@@ -783,7 +789,9 @@ write_callback(int fd, int what, void *v)
}
FALLTHROUGH;
case EAGAIN:
/* not an error */
/* Not an error, re-enable writer. */
if (sudo_ev_add(evbase, iob->wevent, NULL, false) == -1)
sudo_fatal("%s", U_("unable to add event to queue"));
break;
default:
/* XXX - need a way to distinguish non-exec error. */
@@ -821,6 +829,8 @@ write_callback(int fd, int what, void *v)
}
}
}
debug_return;
}
static void