master - cov: ensure vars are set
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=251366146727aac97af...
Commit: 251366146727aac97af5de2eef855860d14910ca
Parent: cbbdace00610ae25a5db8a7156b7d3a2779e4e0b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 15:27:45 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: ensure vars are set
Make sure, tmp_begin and tmp_end are always set, even for blind
coverity.
---
device_mapper/libdm-report.c | 2 +-
libdm/libdm-report.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/device_mapper/libdm-report.c b/device_mapper/libdm-report.c
index cbd0d16..85d3d0f 100644
--- a/device_mapper/libdm-report.c
+++ b/device_mapper/libdm-report.c
@@ -2381,7 +2381,7 @@ static const char *_get_reserved(struct dm_report *rh, unsigned type,
{
const struct dm_report_reserved_value *iter = implicit ? NULL : rh->reserved_values;
const struct dm_report_field_reserved_value *frv;
- const char *tmp_begin, *tmp_end, *tmp_s = s;
+ const char *tmp_begin = NULL, *tmp_end = NULL, *tmp_s = s;
const char *name = NULL;
char c;
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 01255b4..a447017 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -2380,7 +2380,7 @@ static const char *_get_reserved(struct dm_report *rh, unsigned type,
{
const struct dm_report_reserved_value *iter = implicit ? NULL : rh->reserved_values;
const struct dm_report_field_reserved_value *frv;
- const char *tmp_begin, *tmp_end, *tmp_s = s;
+ const char *tmp_begin = NULL, *tmp_end = NULL, *tmp_s = s;
const char *name = NULL;
char c;
5 years, 5 months
master - cov: dm node message fix missing initilization
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cbbdace00610ae25a5d...
Commit: cbbdace00610ae25a5db8a7156b7d3a2779e4e0b
Parent: 253989ecd953b1afcaea43fa0515c55bc6533cd2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 15:24:51 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: dm node message fix missing initilization
In 2 teoretical error path the 'r' value has not been set to
proper value before possible use in error path.
---
device_mapper/libdm-deptree.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/device_mapper/libdm-deptree.c b/device_mapper/libdm-deptree.c
index f49675c..26251f8 100644
--- a/device_mapper/libdm-deptree.c
+++ b/device_mapper/libdm-deptree.c
@@ -1487,7 +1487,7 @@ static int _node_message(uint32_t major, uint32_t minor,
int expected_errno, const char *message)
{
struct dm_task *dmt;
- int r;
+ int r = 0;
if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
return_0;
5 years, 5 months
master - cov: fix error path
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=253989ecd953b1afcae...
Commit: 253989ecd953b1afcaea43fa0515c55bc6533cd2
Parent: 13c49033ede4bb57878361e5ae04c96d4930e9fa
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 15:20:45 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: fix error path
Avoid calling 'bad:' section since we have not set 'fd' yet
and instead directly return failing 0 value.
---
lib/metadata/vdo_manip.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c
index 0b3ed19..c0446ad 100644
--- a/lib/metadata/vdo_manip.c
+++ b/lib/metadata/vdo_manip.c
@@ -102,7 +102,7 @@ static int _sysfs_get_kvdo_value(const char *dm_name, const char *vdo_param, uin
if (dm_snprintf(path, sizeof(path), "%skvdo/%s/%s",
dm_sysfs_dir(), dm_name, vdo_param) < 0) {
log_error("Failed to build kmod path.");
- goto bad;
+ return 0;
}
if ((fd = open(path, O_RDONLY)) < 0) {
5 years, 5 months
master - cov: fix failing filter initialization
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=13c49033ede4bb57878...
Commit: 13c49033ede4bb57878361e5ae04c96d4930e9fa
Parent: a7298810d1fd0f64be3fd903e9f9fcce9af7b84c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 15:17:07 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: fix failing filter initialization
When persistent_filter_create() fails, the existing passed filter
should be preserved, so it could be properly deleted on
error path - so new pfilter is assigned instead.
---
lib/commands/toolcontext.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index fa87bcc..9f00593 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1167,7 +1167,7 @@ bad:
*/
int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
{
- struct dev_filter *filter = NULL, *filter_components[2] = {0};
+ struct dev_filter *pfilter, *filter = NULL, *filter_components[2] = {0};
if (!cmd->initialized.connections) {
log_error(INTERNAL_ERROR "connections must be initialized before filters");
@@ -1192,12 +1192,12 @@ int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
filter = cmd->lvmetad_filter;
cmd->lvmetad_filter = NULL;
- if (!(filter = persistent_filter_create(cmd->dev_types, filter))) {
+ if (!(pfilter = persistent_filter_create(cmd->dev_types, filter))) {
log_verbose("Failed to create persistent device filter.");
goto bad;
}
- cmd->filter = filter;
+ cmd->filter = filter = pfilter;
cmd->full_filter = filter;
5 years, 5 months
master - cov: fix typo
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a7298810d1fd0f64be3...
Commit: a7298810d1fd0f64be3fd903e9f9fcce9af7b84c
Parent: eb566e034fecd27ced0dc1133e19ced2636b3714
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 15:11:34 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: fix typo
Avoid double assing same value.
---
device_mapper/vdo/status.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/device_mapper/vdo/status.c b/device_mapper/vdo/status.c
index 6831195..c86c911 100644
--- a/device_mapper/vdo/status.c
+++ b/device_mapper/vdo/status.c
@@ -184,7 +184,7 @@ static bool _parse_field(const char **b, const char *e,
bool dm_vdo_status_parse(struct dm_pool *mem, const char *input,
struct dm_vdo_status_parse_result *result)
{
- const char *b = b = input;
+ const char *b = input;
const char *e = input + strlen(input);
const char *te;
struct dm_vdo_status *s;
5 years, 5 months
master - cov: add check for positive value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=eb566e034fecd27ced0...
Commit: eb566e034fecd27ced0dc1133e19ced2636b3714
Parent: 9b7121226258f7dfe759cc1f8625cbfb80fec161
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 15:02:09 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: add check for positive value
As pgsize parameter for _init_free_list() can't be negative,
report problem in case for any reason we would get negative number.
---
lib/device/bcache.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 43ca63e..8b2c7f8 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -881,6 +881,11 @@ struct bcache *bcache_create(sector_t block_sectors, unsigned nr_cache_blocks,
unsigned max_io = engine->max_io(engine);
long pgsize = sysconf(_SC_PAGESIZE);
+ if (pgsize < 0) {
+ log_warn("WARNING: _SC_PAGESIZE returns negative value.");
+ return NULL;
+ }
+
if (!nr_cache_blocks) {
log_warn("bcache must have at least one cache block");
return NULL;
5 years, 5 months
master - cov: add at least ASSERT
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=30b1b575067bcab27ab...
Commit: 30b1b575067bcab27ab1788247754b183387f55e
Parent: eed8715e1d891665a6c9b8a39850e61f40ea453e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 14:53:36 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: add at least ASSERT
Seems lot of code here can't handle failing allocation.
Meanwhile before bigger fix put in asserts in place.
---
base/data-struct/radix-tree-adaptive.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/base/data-struct/radix-tree-adaptive.c b/base/data-struct/radix-tree-adaptive.c
index cbe8302..f5a8606 100644
--- a/base/data-struct/radix-tree-adaptive.c
+++ b/base/data-struct/radix-tree-adaptive.c
@@ -564,6 +564,8 @@ static void _degrade_to_n4(struct node16 *n16, struct value *result)
{
struct node4 *n4 = zalloc(sizeof(*n4));
+ assert(n4 != NULL);
+
n4->nr_entries = n16->nr_entries;
memcpy(n4->keys, n16->keys, n16->nr_entries * sizeof(*n4->keys));
memcpy(n4->values, n16->values, n16->nr_entries * sizeof(*n4->values));
@@ -578,6 +580,8 @@ static void _degrade_to_n16(struct node48 *n48, struct value *result)
unsigned i, count = 0;
struct node16 *n16 = zalloc(sizeof(*n16));
+ assert(n16 != NULL);
+
n16->nr_entries = n48->nr_entries;
for (i = 0; i < 256; i++) {
if (n48->keys[i] < 48) {
@@ -598,6 +602,8 @@ static void _degrade_to_n48(struct node256 *n256, struct value *result)
unsigned i, count = 0;
struct node48 *n48 = zalloc(sizeof(*n48));
+ assert(n48 != NULL);
+
n48->nr_entries = n256->nr_entries;
for (i = 0; i < 256; i++) {
if (n256->values[i].type == UNSET)
5 years, 5 months
master - cov: dmstats check for failing malloc
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b7121226258f7dfe75...
Commit: 9b7121226258f7dfe759cc1f8625cbfb80fec161
Parent: 30b1b575067bcab27ab1788247754b183387f55e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 14:58:24 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: dmstats check for failing malloc
Add missing check for allocation success.
---
libdm/dm-tools/dmsetup.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index fb1a574..835fdcd 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -5224,7 +5224,10 @@ static int _do_stats_create_regions(struct dm_stats *dms,
if (!segments || (info.target_count == 1))
region_ids = ®ion_id;
else
- region_ids = malloc(info.target_count * sizeof(*region_ids));
+ if (!(region_ids = malloc(info.target_count * sizeof(*region_ids)))) {
+ log_error("Failed to allocated region IDs.");
+ goto out;
+ }
do {
uint64_t segment_start, segment_len;
5 years, 5 months
master - cov: dm stats missed terminating null
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=20971f7034cbd329f87...
Commit: 20971f7034cbd329f873e08869bfb7acf3f1ac0e
Parent: 77aa055e8a34eb7f0036b6240f3f93dc429c0c02
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 14:45:16 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: dm stats missed terminating null
Coverity noticed allocating insufficient memory
for the terminating null of the string.
---
libdm/libdm-stats.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index e9bfa9d..ea8fdf2 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -1009,7 +1009,7 @@ static int _stats_parse_list(struct dm_stats *dms, const char *resp)
* dm_task_get_message_response() returns a 'const char *' but
* since fmemopen also permits "w" it expects a 'char *'.
*/
- if (!(list_rows = fmemopen((char *)resp, strlen(resp), "r")))
+ if (!(list_rows = fmemopen((char *)resp, strlen(resp) + 1, "r")))
return_0;
/* begin region table */
@@ -1240,7 +1240,7 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
* dm_task_get_message_response() returns a 'const char *' but
* since fmemopen also permits "w" it expects a 'char *'.
*/
- stats_rows = fmemopen((char *)resp, strlen(resp), "r");
+ stats_rows = fmemopen((char *)resp, strlen(resp) + 1, "r");
if (!stats_rows)
goto_bad;
5 years, 5 months
master - cov: fix missing null allocation check
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=eed8715e1d891665a6c...
Commit: eed8715e1d891665a6c9b8a39850e61f40ea453e
Parent: 20971f7034cbd329f873e08869bfb7acf3f1ac0e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 15 14:52:49 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200
cov: fix missing null allocation check
---
base/data-struct/radix-tree-adaptive.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/base/data-struct/radix-tree-adaptive.c b/base/data-struct/radix-tree-adaptive.c
index cd53dd6..cbe8302 100644
--- a/base/data-struct/radix-tree-adaptive.c
+++ b/base/data-struct/radix-tree-adaptive.c
@@ -265,7 +265,8 @@ static bool _insert_prefix_chain(struct radix_tree *rt, struct value *v, uint8_t
if (kb[i] != pc->prefix[i])
break;
- pc2 = zalloc(sizeof(*pc2) + pc->len - i);
+ if (!(pc2 = zalloc(sizeof(*pc2) + pc->len - i)))
+ return false;
pc2->len = pc->len - i;
memmove(pc2->prefix, pc->prefix + i, pc2->len);
pc2->child = pc->child;
5 years, 5 months