]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs: check if cxt->dir_path is NULL in sysfs_readlink()
authorCong Wang <xiyou.wangcong@gmail.com>
Wed, 20 Jun 2012 08:32:00 +0000 (16:32 +0800)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Jun 2012 06:21:23 +0000 (08:21 +0200)
cxt->dir_path could be NULL, for example, when sysfs_init() fails,
check this before calling readlink()/readlink_at().

Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
lib/sysfs.c

index 312191f034e98869bf72c697b95b6b2a1efc7ce3..b4fb7cdda6115a2d09887d1333d601e8af23f3f3 100644 (file)
@@ -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);