All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch] lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink()
@ 2012-06-20  8:32 Cong Wang
  2012-06-21  8:43 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Wang @ 2012-06-20  8:32 UTC (permalink / raw)
  To: util-linux; +Cc: Cong Wang, Karel Zak

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink()
  2012-06-20  8:32 [Patch] lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink() Cong Wang
@ 2012-06-21  8:43 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-06-21  8:43 UTC (permalink / raw)
  To: Cong Wang; +Cc: util-linux, Cong Wang

On Wed, Jun 20, 2012 at 04:32:00PM +0800, Cong Wang wrote:
> cxt->dir_path could be NULL, for example, when sysfs_init() fails,
> check this before calling readlink()/readlink_at().

 Applied, thanks.

 I have also added warn_unused_result attribute to sysfs_init() to
 make sure that cxt is everywhere initialized.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-21  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-20  8:32 [Patch] lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink() Cong Wang
2012-06-21  8:43 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.