mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-20 19:52:16 +00:00
Fix NULL pointer dereference in uev_timer_init()
uev_timer_init() crashes when called without a watcher:
uev_timer_init(ctx, NULL, cb, NULL, 100, 0);
The cleanup after a failed setup resets the descriptor in the watcher
without checking that there is one.
Check the arguments first, like the other watcher types do.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
2 files changed
+16
No files matched your search
@@ -78,6 +78,11 @@ int uev_timer_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeou
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
if (!w || !ctx) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (timeout < 0 || period < 0) {
|
if (timeout < 0 || period < 0) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -41,9 +41,20 @@ static void ctx_init(void)
|
|||||||
fail_unless(ctx.fd == -1);
|
fail_unless(ctx.fd == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Invalid arguments must not crash */
|
||||||
|
static void null_init(void)
|
||||||
|
{
|
||||||
|
uev_ctx_t ctx;
|
||||||
|
|
||||||
|
fail_unless(uev_init(&ctx) == 0);
|
||||||
|
fail_unless(uev_timer_init(&ctx, NULL, NULL, NULL, 100, 0) != 0);
|
||||||
|
fail_unless(uev_exit(&ctx) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
event_init();
|
event_init();
|
||||||
|
null_init();
|
||||||
ctx_init();
|
ctx_init();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in new issue
Block a user