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>
This commit is contained in:
Cong Wang 2012-06-20 16:32:00 +08:00 committed by Karel Zak
parent 95f9f3098e
commit cffee0de0c
1 changed files with 3 additions and 0 deletions

View 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);