]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
sysfs: avoid possible data corruption in sys_load.
authorNeilBrown <neilb@suse.de>
Fri, 18 Jul 2008 06:37:18 +0000 (16:37 +1000)
committerNeilBrown <neilb@suse.de>
Fri, 18 Jul 2008 06:37:18 +0000 (16:37 +1000)
Don't retry to remove a newline from the end of an empty string.

Signed-off-by: Neil Brown <neilb@suse.de>
sysfs.c

diff --git a/sysfs.c b/sysfs.c
index bc021cc7fae3d07e714f9ad390803f643e2f2bf2..8979ec4e23c80fd1812fe6b4f277cc4ad325d923 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -37,7 +37,7 @@ int load_sys(char *path, char *buf)
        if (n <0 || n >= 1024)
                return -1;
        buf[n] = 0;
-       if (buf[n-1] == '\n')
+       if (n && buf[n-1] == '\n')
                buf[n-1] = 0;
        return 0;
 }