lib/sysfs.c: check if cxt->dir_path is NULL in sysfs_readlink()
Subsystems (2)
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().
Cc Karel Zak <[email protected]>
Signed-off-by Cong Wang <[email protected]>
---
lib/sysfs.c +3 -0
@@ -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);
Quoted 2 lines · Cong Wang
cxt->dir_pathcould be NULL, for example, whensysfs_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