From: Cong Wang <amwang@redhat.com>
To: util-linux@vger.kernel.org
Cc: Cong Wang <xiyou.wangcong@gmail.com>, Karel Zak <kzak@redhat.com>
Subject: [Patch] lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink()
Date: Wed, 20 Jun 2012 16:32:00 +0800 [thread overview]
Message-ID: <1340181120-3457-1-git-send-email-amwang@redhat.com> (raw)
From: Cong Wang <xiyou.wangcong@gmail.com>
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>
---
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);
next reply other threads:[~2012-06-20 8:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-20 8:32 Cong Wang [this message]
2012-06-21 8:43 ` [Patch] lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink() Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340181120-3457-1-git-send-email-amwang@redhat.com \
--to=amwang@redhat.com \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).