From: Cong Wang <xiyou.wangcong@xxxxxxxxx> cxt->dir_path could be NULL, for example, when sysfs_init() fails, check this before calling readlink()/readlink_at(). Cc: Karel Zak <kzak@xxxxxxxxxx> Signed-off-by: Cong Wang <xiyou.wangcong@xxxxxxxxx> --- diff --git a/lib/sysfs.c b/lib/sysfs.c index 312191f..b4fb7cd 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -220,6 +220,9 @@ static int sysfs_open(struct sysfs_cxt *cxt, const char *attr) ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr, char *buf, size_t bufsiz) { + if (!cxt->dir_path) + return -1; + if (attr) return readlink_at(cxt->dir_fd, cxt->dir_path, attr, buf, bufsiz); -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html