1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 01:55:10 +03:00

coverity: fix memory access

Commit  52e0d0db44 introduced regression
as code may access   buf[0 - 1].

Reorder code to first remove '\n' and then check buffer size for
empty.
This commit is contained in:
Zdenek Kabelac 2016-04-21 20:21:59 +02:00
parent 556eba1835
commit cbf99be43a
2 changed files with 7 additions and 10 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.151 -
=================================
Fix memory access for empty sysfs values (2.02.149).
Disable lvmetad when lvm1 metadata is seen, so commands revert to scanning.
Suppress errors when snapshot merge gets delayed because volume is in use.
Avoid internal snapshot LV names in messages.

View File

@ -379,17 +379,13 @@ static int _get_sysfs_value(const char *path, char *buf, size_t buf_size, int er
goto out;
}
if (!(len = strlen(buf)) || (len == 1 && buf[0] == '\n')) {
if (error_if_no_value) {
log_error("_get_sysfs_value: %s: no value", path);
goto out;
}
}
if ((len = strlen(buf)) && buf[len - 1] == '\n')
buf[--len] = '\0';
if (buf[len - 1] == '\n')
buf[len - 1] = '\0';
r = 1;
if (!len && error_if_no_value)
log_error("_get_sysfs_value: %s: no value", path);
else
r = 1;
out:
if (fclose(fp))
log_sys_error("fclose", path);