From 5c055d64730a640643d076e68d59cf884456b7ee Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 9 Jan 2017 12:54:54 +0100 Subject: [PATCH] core: fix segfault in gpiod_line_find_by_name() We need to check whether gpiod_line_name() didn't return NULL. Signed-off-by: Bartosz Golaszewski --- core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core.c b/core.c index de5dff2..78e25f2 100644 --- a/core.c +++ b/core.c @@ -513,6 +513,7 @@ struct gpiod_line * gpiod_line_find_by_name(const char *name) struct gpiod_line_iter line_iter; struct gpiod_chip *chip; struct gpiod_line *line; + const char *line_name; chip_iter = gpiod_chip_iter_new(); if (!chip_iter) @@ -521,6 +522,10 @@ struct gpiod_line * gpiod_line_find_by_name(const char *name) gpiod_foreach_chip(chip_iter, chip) { gpiod_line_iter_init(&line_iter, chip); gpiod_foreach_line(&line_iter, line) { + line_name = gpiod_line_name(line); + if (!line_name) + continue; + if (strcmp(gpiod_line_name(line), name) == 0) { /* TODO A separate function for that maybe? */ closedir(chip_iter->dir); -- 2.30.2