diff options
| author | Cong Wang <xiyou.wangcong@gmail.com> | 2012-06-20 16:32:00 +0800 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2012-06-21 08:21:23 +0200 |
| commit | cffee0de0cf7c0d44323a830beb313d5ae18247d (patch) | |
| tree | c5e52c83a05cd8b4dd7aba9e2deed31e9a12eb7a | |
| parent | 95f9f3098ec274d7d50a0bd57f6afdf62e7bb109 (diff) | |
| download | util-linux-cffee0de0cf7c0d44323a830beb313d5ae18247d.tar.gz | |
lib/sysfs: check if cxt->dir_path is NULL in sysfs_readlink()
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>
| -rw-r--r-- | lib/sysfs.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c index 312191f034..b4fb7cdda6 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); |
