master - report: add extra pointer check
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4f8f8fcb52d1d1...
Commit: 4f8f8fcb52d1d1f2a46468aa6bb4a8da11804c5b
Parent: 856e11e11c3b3ba4da3cbbd21982d34daa51aaa0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 8 17:19:21 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:20 2015 +0100
report: add extra pointer check
Coverity was seeing possible trouble with NULL pointer dereference.
So ensure it may never happen.
---
lib/report/report.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 911c96e..91522b1 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -960,13 +960,13 @@ static int _translate_time_items(struct dm_report *rh, struct time_info *info,
t += (multiplier * SECS_PER_HOUR);
break;
case TIME_UNIT_AM:
- if (ti_p->prop->id == TIME_NUM_MULTIPLIER)
+ if (ti_p && ti_p->prop->id == TIME_NUM_MULTIPLIER)
tm.tm_hour = multiplier;
break;
case TIME_UNIT_PM:
- if (_is_time_unit(ti_p->prop->id))
+ if (ti_p && _is_time_unit(ti_p->prop->id))
t -= 12 * SECS_PER_HOUR;
- else if (ti_p->prop->id == TIME_NUM_MULTIPLIER)
+ else if (ti_p && ti_p->prop->id == TIME_NUM_MULTIPLIER)
tm.tm_hour = multiplier + 12;
break;
case TIME_UNIT_DAY:
8 years, 6 months
master - lv_manip: do not deref NULL for debug message
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=856e11e11c3b3b...
Commit: 856e11e11c3b3ba4da3cbbd21982d34daa51aaa0
Parent: fa1d73084769ea4a6d07434e12dcae519938e4c5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:28:59 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:20 2015 +0100
lv_manip: do not deref NULL for debug message
Coverity: when 'pv2' would be passed as NULL, do not try to
deref it in debug message.
---
WHATS_NEW | 1 +
lib/metadata/lv_manip.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 19f24f7..7930631 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.135 -
====================================
+ Do not deref NULL pointer in debug message for _match_pv_tags().
Drop unneeded stat() call when checking for sysfs file.
Fix memory leak on error path of failing thin-pool percentage check.
Add missing test for failing node allocation in lvmetad.
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 3c72c08..e23a8b9 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2114,7 +2114,7 @@ static int _match_pv_tags(const struct dm_config_node *cling_tag_list_cn,
else {
if (!pv_tags)
log_debug_alloc("Matched allocation PV tag %s on existing %s with free space on %s.",
- tag_matched, pv_dev_name(pv1), pv_dev_name(pv2));
+ tag_matched, pv_dev_name(pv1), pv2 ? pv_dev_name(pv2) : "-");
else
log_debug_alloc("Eliminating allocation area %" PRIu32 " at PV %s start PE %" PRIu32
" from consideration: PV tag %s already used.",
8 years, 6 months
master - dev-type: fix TOCTOU order
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fa1d73084769ea...
Commit: fa1d73084769ea4a6d07434e12dcae519938e4c5
Parent: 80c3fb786cc236f200026624ded4c668b37ef22d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 8 17:15:24 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:20 2015 +0100
dev-type: fix TOCTOU order
Doing 'stat' checking first and later opening is racy.
And since we do not really care about any 'status' info
here and we read 'sysfs' here - just drop whole 'stat()'
call and directly handle error from failing 'fopen()'.
---
WHATS_NEW | 1 +
lib/device/dev-type.c | 13 +++----------
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 6368b32..19f24f7 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.135 -
====================================
+ Drop unneeded stat() call when checking for sysfs file.
Fix memory leak on error path of failing thin-pool percentage check.
Add missing test for failing node allocation in lvmetad.
Correct configure messages when enabling/disabling lvmlockd.
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index a66ef95..e1243bd 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -462,7 +462,6 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)
*result = dev->dev;
ret = 1;
goto out; /* dev is not a partition! */
-
}
/*
@@ -486,17 +485,11 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)
}
/* finally, parse 'dev' attribute and create corresponding dev_t */
- if (stat(path, &info) == -1) {
+ if (!(fp = fopen(path, "r"))) {
if (errno == ENOENT)
- log_error("sysfs file %s does not exist", path);
+ log_error("sysfs file %s does not exist.", path);
else
- log_sys_error("stat", path);
- goto out;
- }
-
- fp = fopen(path, "r");
- if (!fp) {
- log_sys_error("fopen", path);
+ log_sys_error("fopen", path);
goto out;
}
8 years, 6 months
master - thin: fix error path mem leak
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=80c3fb786cc236...
Commit: 80c3fb786cc236f200026624ded4c668b37ef22d
Parent: 3cadc1c87e4f1f6cede3895a7f7f28f37eaf9648
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 8 17:04:03 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
thin: fix error path mem leak
Coverity: when parsing of thin-pool status would have failed,
it could have leaked memory pool and dmt struct.
---
WHATS_NEW | 1 +
lib/activate/dev_manager.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index d0a1476..6368b32 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.135 -
====================================
+ Fix memory leak on error path of failing thin-pool percentage check.
Add missing test for failing node allocation in lvmetad.
Correct configure messages when enabling/disabling lvmlockd.
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 964eef5..6ec9d22 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -567,7 +567,7 @@ static int _ignore_unusable_thins(struct device *dev)
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
if (!dm_get_status_thin_pool(mem, params, &status))
- return_0;
+ goto_out;
if (status->read_only || status->out_of_data_space) {
log_warn("WARNING: %s: Thin's thin-pool needs inspection.",
8 years, 6 months
master - libdm: add test for dm_task_get_message_response()
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3cadc1c87e4f1f...
Commit: 3cadc1c87e4f1f6cede3895a7f7f28f37eaf9648
Parent: 84303dc17aeca9773d5644e4beccc267ab7a3153
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:50:46 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
libdm: add test for dm_task_get_message_response()
Coverity notices dm_task_get_message_response() result should be
checked for NULL which should not be passed to dm_pool_strdup().
---
WHATS_NEW_DM | 1 +
libdm/libdm-stats.c | 6 +++++-
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index c735194..795776b 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.111 -
====================================
+ Test dm_task_get_message_response for !NULL in dm_stats_print_region().
Add checks for failing dm_stats_create() in dmsetup.
Add missing fifo close when failed to initialize client connection.
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index 43479d9..505b062 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -1259,6 +1259,7 @@ char *dm_stats_print_region(struct dm_stats *dms, uint64_t region_id,
{
char *resp = NULL;
struct dm_task *dmt = NULL;
+ const char *response;
if (!_stats_bound(dms))
return_0;
@@ -1269,7 +1270,10 @@ char *dm_stats_print_region(struct dm_stats *dms, uint64_t region_id,
if (!dmt)
return_0;
- resp = dm_pool_strdup(dms->mem, dm_task_get_message_response(dmt));
+ if (!(response = dm_task_get_message_response(dmt)))
+ return_0;
+
+ resp = dm_pool_strdup(dms->mem, response);
dm_task_destroy(dmt);
if (!resp)
8 years, 6 months
master - libdm: exlicitly check for NULL
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=84303dc17aeca9...
Commit: 84303dc17aeca9773d5644e4beccc267ab7a3153
Parent: f6c140e200177ef527c8943fbe0a94e2e6bd8b3f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:44:26 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
libdm: exlicitly check for NULL
Coverity: another explict check for NULL, where coverity fails to
see it.
---
libdm/libdm-report.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index b2e70d5..23d0955 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -437,7 +437,8 @@ static int _report_field_string_list(struct dm_report *rh,
/* one item */
if (list_size == 1) {
sl = (struct dm_str_list *) dm_list_first(data);
- if (!(sort_value->value = field->report_string = dm_pool_strdup(rh->mem, sl->str))) {
+ if (!sl ||
+ !(sort_value->value = field->report_string = dm_pool_strdup(rh->mem, sl->str))) {
log_error("dm_report_field_string_list: dm_pool_strdup failed");
goto out;
}
@@ -2218,6 +2219,7 @@ static const char *_tok_value_number(const char *s,
int is_float = 0;
*begin = s;
+ /* coverity[assign_where_compare_meant] */
while ((!is_float && (*s == '.') && ((is_float = 1))) || isdigit(*s))
s++;
*end = s;
8 years, 6 months
master - libdm: ensure vars are initialized
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f6c140e200177e...
Commit: f6c140e200177ef527c8943fbe0a94e2e6bd8b3f
Parent: b1c4017743060a25a6a263244d9d0e18c09acda5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 8 17:21:22 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
libdm: ensure vars are initialized
Coverity found potential error path, where code could
have used some unset variables.
---
libdm/libdm-stats.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index d3ae1f2..43479d9 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -822,7 +822,7 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
struct dm_pool *mem = dms->mem;
struct dm_stats_counters cur;
FILE *stats_rows = NULL;
- uint64_t start, len;
+ uint64_t start = 0, len = 0;
char row[256];
int r;
@@ -2305,6 +2305,10 @@ const char *dm_histogram_to_string(const struct dm_histogram *dmh, int bin,
} else if (bounds)
len = dm_snprintf(buf, sizeof(buf), "%s%s", bounds_buf,
sep);
+ else {
+ *buf = '\0';
+ len = 0;
+ }
if (len < 0)
goto_bad;
8 years, 6 months
master - libdm: add missing error path check
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b1c4017743060a...
Commit: b1c4017743060a25a6a263244d9d0e18c09acda5
Parent: 18fd0bd20ce1d4a7d2bd27b2c9981a402f9bcd2e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:31:59 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
libdm: add missing error path check
Coverity: do not continue with section cloning when root node
would a NULL.
---
libdm/libdm-config.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index c8984b2..df314a0 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -563,7 +563,8 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node *
return NULL;
}
- root = _find_or_make_node(p->mem, parent, str);
+ if (!(root = _find_or_make_node(p->mem, parent, str)))
+ return_NULL;
if (p->t == TOK_SECTION_B) {
match(TOK_SECTION_B);
8 years, 6 months
master - lvconvert: add extra check for existance of pointer
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=18fd0bd20ce1d4...
Commit: 18fd0bd20ce1d4a7d2bd27b2c9981a402f9bcd2e
Parent: b83a20b80a1f2f239e5c8496e819edd039965a6c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:48:17 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
lvconvert: add extra check for existance of pointer
Coverity here is not fully-in-picture - but please it
with validation of pointer which currently cannot be null,
since we always return at least empty string.
---
tools/lvconvert.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index a7df26d..c6cea0d 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2340,7 +2340,7 @@ static int _lvconvert_pool_repair(struct cmd_context *cmd,
struct pipe_data pdata;
FILE *f;
- if (!thin_repair[0]) {
+ if (!thin_repair || !thin_repair[0]) {
log_error("Thin repair commnand is not configured. Repair is disabled.");
return 0; /* Checking disabled */
}
8 years, 6 months
master - lvmetad: validate mda is not NULL
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b83a20b80a1f2f...
Commit: b83a20b80a1f2f239e5c8496e819edd039965a6c
Parent: 99def8f43912958bb8567a123b9725c0e3389048
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:43:09 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:19 2015 +0100
lvmetad: validate mda is not NULL
Coverity: make it explicitely obvious metadata area is not NULL.
---
lib/cache/lvmetad.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index c859413..5c10cf4 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -1310,6 +1310,7 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev,
struct _lvmetad_pvscan_baton baton;
/* Create a dummy instance. */
struct format_instance_ctx fic = { .type = 0 };
+ struct metadata_area *mda;
if (!lvmetad_active()) {
log_error("Cannot proceed since lvmetad is not active.");
@@ -1353,8 +1354,11 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev,
* Note that the single_device parameter also gets ignored and this code
* can scan further devices.
*/
- if (!baton.vg && !(baton.fid->fmt->features & FMT_MDAS))
- baton.vg = ((struct metadata_area *) dm_list_first(&baton.fid->metadata_areas_in_use))->ops->vg_read(baton.fid, lvmcache_vgname_from_info(info), NULL, NULL, NULL, 1);
+ if (!baton.vg && !(baton.fid->fmt->features & FMT_MDAS)) {
+ if ((mda = (struct metadata_area *)dm_list_first(&baton.fid->metadata_areas_in_use)))
+ baton.vg = mda->ops->vg_read(baton.fid, lvmcache_vgname_from_info(info),
+ NULL, NULL, NULL, 1);
+ }
if (!baton.vg)
lvmcache_fmt(info)->ops->destroy_instance(baton.fid);
8 years, 6 months