Skip to contentSkip to conversation

lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink()

PATCH Applied Cong Wang 2 participants 2 messages Jun 20, 2012 – Jun 21, 2012

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink()

From: Cong Wang <[email protected]>

cxt->dir_path could be NULL, for example, when sysfs_init() fails, check this before calling readlink()/readlink_at().

---

lib/sysfs.c +3 -0
index 312191f..b4fb7cd 100644
@@ -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);
 
maintainer Applied
#1 lore raw
Quoted 2 lines · Cong Wang

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

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com