From: Bartosz Golaszewski Date: Wed, 6 Mar 2019 15:03:34 +0000 (+0100) Subject: core: ctxless: bail-out if num_lines == 0 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=6082134bac02d4619c8b637ae9e0bb886e6159cd;p=qemu-gpiodev%2Flibgpiod.git core: ctxless: bail-out if num_lines == 0 Return -1 and set errno to EINVAL if the number of lines specified in any context-less helper is 0. This is done in addition to bailing out when the number is higher than the maximum supported number of GPIO lines. This fixes the segfaults that currently ocurr for num_lines == 0. Signed-off-by: Bartosz Golaszewski --- diff --git a/src/lib/ctxless.c b/src/lib/ctxless.c index a0681a5..d90a3e0 100644 --- a/src/lib/ctxless.c +++ b/src/lib/ctxless.c @@ -38,7 +38,7 @@ int gpiod_ctxless_get_value_multiple(const char *device, int rv, flags; unsigned int i; - if (num_lines > GPIOD_LINE_BULK_MAX_LINES) { + if (!num_lines || num_lines > GPIOD_LINE_BULK_MAX_LINES) { errno = EINVAL; return -1; } @@ -95,7 +95,7 @@ int gpiod_ctxless_set_value_multiple(const char *device, unsigned int i; int rv, flags; - if (num_lines > GPIOD_LINE_BULK_MAX_LINES) { + if (!num_lines || num_lines > GPIOD_LINE_BULK_MAX_LINES) { errno = EINVAL; return -1; } @@ -142,7 +142,7 @@ static int basic_event_poll(unsigned int num_lines, unsigned int i; int rv, ret; - if (num_lines > GPIOD_LINE_BULK_MAX_LINES) + if (!num_lines || num_lines > GPIOD_LINE_BULK_MAX_LINES) return GPIOD_CTXLESS_EVENT_POLL_RET_ERR; memset(poll_fds, 0, sizeof(poll_fds)); @@ -235,7 +235,7 @@ int gpiod_ctxless_event_monitor_multiple( struct gpiod_line *line; unsigned int i; - if (num_lines > GPIOD_LINE_BULK_MAX_LINES) { + if (!num_lines || num_lines > GPIOD_LINE_BULK_MAX_LINES) { errno = EINVAL; return -1; }