summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2015-07-06 13:21:33 +1000
committerNeilBrown <neilb@suse.de>2015-07-06 13:21:33 +1000
commit5418499ae48851399c280ca1986741762bd039f9 (patch)
treec50767daaa45df546402618f2b3cb0c4c455af94
parentbcbb92d4ee8e90d5b97b0446a064a918cf0fcf2b (diff)
downloadmdadm-5418499ae48851399c280ca1986741762bd039f9.tar.gz
sysfs: reject reads that use the whole buffer.
If a read fills the whole buffer, then we possibly missed something of the end, and we definitely shouldn't put a '\0' beyond the end, so just return an error. This should never happen anyway. Signed-off-by: NeilBrown <neilb@suse.com>
-rw-r--r--sysfs.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sysfs.c b/sysfs.c
index 18f3df9..7268470 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -490,7 +490,7 @@ int sysfs_fd_get_ll(int fd, unsigned long long *val)
lseek(fd, 0, 0);
n = read(fd, buf, sizeof(buf));
- if (n <= 0)
+ if (n <= 0 || n == sizeof(buf))
return -2;
buf[n] = 0;
*val = strtoull(buf, &ep, 0);
@@ -526,7 +526,7 @@ int sysfs_fd_get_two(int fd, unsigned long long *v1, unsigned long long *v2)
lseek(fd, 0, 0);
n = read(fd, buf, sizeof(buf));
- if (n <= 0)
+ if (n <= 0 || n == sizeof(buf))
return -2;
buf[n] = 0;
*v1 = strtoull(buf, &ep, 0);
@@ -562,7 +562,7 @@ int sysfs_fd_get_str(int fd, char *val, int size)
lseek(fd, 0, 0);
n = read(fd, val, size);
- if (n <= 0)
+ if (n <= 0 || n == size)
return -1;
val[n] = 0;
return n;
@@ -715,7 +715,7 @@ int sysfs_disk_to_sg(int fd)
struct stat st;
char path[256];
char sg_path[256];
- char sg_major_minor[8];
+ char sg_major_minor[10];
char *c;
DIR *dir;
struct dirent *de;
@@ -750,7 +750,7 @@ int sysfs_disk_to_sg(int fd)
rv = read(fd, sg_major_minor, sizeof(sg_major_minor));
close(fd);
- if (rv < 0)
+ if (rv < 0 || rv == sizeof(sg_major_minor))
return -1;
else
sg_major_minor[rv - 1] = '\0';