mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-14 19:03:42 +00:00
Fix #27: possible buffer overrun in uev_run()
If uev_init1() is called with maxevents > 10 the call to epoll_wait() might cause buffer overflow. Reported by Steve Palmer. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
f9c72a01c8
commit
2d9f1c9ce6
1 file changed
+11
-4
@@ -196,11 +196,11 @@ int uev_init(uev_ctx_t *ctx)
|
|||||||
/**
|
/**
|
||||||
* Create an event loop context
|
* Create an event loop context
|
||||||
* @param ctx Pointer to an uev_ctx_t context to be initialized
|
* @param ctx Pointer to an uev_ctx_t context to be initialized
|
||||||
* @param maxevents Maximum number of events in event cache
|
* @param maxevents Maximum number of events in event cache [1, 10]
|
||||||
*
|
*
|
||||||
* This function is the same as uev_init() except for the @p maxevents
|
* This function is the same as uev_init() except for the @p maxevents
|
||||||
* argument, which controls the number of events in the event cache
|
* argument, max ::UEV_MAX_EVENTS, which controls the number of events
|
||||||
* returned to the main loop.
|
* in the event cache returned to the main loop.
|
||||||
*
|
*
|
||||||
* In cases where you have multiple events pending in the cache and some
|
* In cases where you have multiple events pending in the cache and some
|
||||||
* event may cause later ones, already sent by the kernel to userspace,
|
* event may cause later ones, already sent by the kernel to userspace,
|
||||||
@@ -222,6 +222,9 @@ int uev_init1(uev_ctx_t *ctx, int maxevents)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxevents > UEV_MAX_EVENTS)
|
||||||
|
maxevents = UEV_MAX_EVENTS;
|
||||||
|
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
ctx->maxevents = maxevents;
|
ctx->maxevents = maxevents;
|
||||||
|
|
||||||
@@ -319,8 +322,12 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
|
|
||||||
while (ctx->running && ctx->watchers) {
|
while (ctx->running && ctx->watchers) {
|
||||||
struct epoll_event ee[UEV_MAX_EVENTS];
|
struct epoll_event ee[UEV_MAX_EVENTS];
|
||||||
|
int maxevents = ctx->maxevents;
|
||||||
int i, nfds, rerun = 0;
|
int i, nfds, rerun = 0;
|
||||||
|
|
||||||
|
if (maxevents > UEV_MAX_EVENTS)
|
||||||
|
maxevents = UEV_MAX_EVENTS;
|
||||||
|
|
||||||
/* Handle special case: `application < file.txt` */
|
/* Handle special case: `application < file.txt` */
|
||||||
if (ctx->workaround) {
|
if (ctx->workaround) {
|
||||||
_UEV_FOREACH(w, ctx->watchers) {
|
_UEV_FOREACH(w, ctx->watchers) {
|
||||||
@@ -341,7 +348,7 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
continue;
|
continue;
|
||||||
ctx->workaround = 0;
|
ctx->workaround = 0;
|
||||||
|
|
||||||
while ((nfds = epoll_wait(ctx->fd, ee, ctx->maxevents, timeout)) < 0) {
|
while ((nfds = epoll_wait(ctx->fd, ee, maxevents, timeout)) < 0) {
|
||||||
if (!ctx->running)
|
if (!ctx->running)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user