summaryrefslogtreecommitdiff
path: root/sysfs.c
diff options
context:
space:
mode:
authorThomas Jarosch <thomas.jarosch@intra2net.com>2011-10-13 11:21:07 +0200
committerNeilBrown <neilb@suse.de>2011-10-17 11:15:04 +1100
commit9cf014ec4055d95f32e028f1a004ea165d90ffe4 (patch)
tree2597622f1c17b2f2aeee3653459a9abc1768013f /sysfs.c
parentb601104eb4a4733a838fb86e9e279fed14ce9d3f (diff)
Fix off-by-one in readlink() buffer size handling
readlink() returns the number of bytes in the buffer. If we do something like len = readlink(path, buf, sizeof(buf)); buf[len] = '\0'; we might write one byte past the end of the buffer. Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'sysfs.c')
-rw-r--r--sysfs.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sysfs.c b/sysfs.c
index e1aaf4d9..a5fcdd03 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -619,7 +619,7 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume)
memset(nm, 0, sizeof(nm));
sprintf(dv, "/sys/dev/block/%d:%d", sd->disk.major, sd->disk.minor);
- rv = readlink(dv, nm, sizeof(nm));
+ rv = readlink(dv, nm, sizeof(nm)-1);
if (rv <= 0)
return -1;
nm[rv] = '\0';