sysfs: avoid possible data corruption in sys_load.

Don't retry to remove a newline from the end of an empty string.

Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
NeilBrown 2008-07-18 16:37:18 +10:00
parent 7364918895
commit 8dfb8619f9
1 changed files with 1 additions and 1 deletions

View File

@ -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;
}