diff options
author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2019-03-06 16:03:34 +0100 |
---|---|---|
committer | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2019-03-06 17:56:30 +0100 |
commit | 511a084cca9a2750c9a3cafbb9def0594dc7df4e (patch) | |
tree | 74bdbeb9365c7fc5bbd685be25cf8e4fcc41df03 | |
parent | 20f8ac440ecdf5ad3508a5ebfefce7983f478eb9 (diff) | |
download | libgpiod-v1.2.x.tar.gz |
core: ctxless: bail-out if num_lines == 0v1.2.x
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 <bgolaszewski@baylibre.com>
-rw-r--r-- | src/lib/ctxless.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/ctxless.c b/src/lib/ctxless.c index 0009504e..ec3ad817 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 status, 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, int status, 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; } @@ -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; } |