master - cleanup: drop unneeded header file
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f6d2528f648b2c...
Commit: f6d2528f648b2cfad0d516fc6f0444a2570579f2
Parent: 5ba219e87a37cd18aa75971370254ed1fbdfde53
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Nov 7 17:16:32 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:51 2015 +0100
cleanup: drop unneeded header file
---
lib/datastruct/str_list.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/lib/datastruct/str_list.c b/lib/datastruct/str_list.c
index 73b5534..f056b85 100644
--- a/lib/datastruct/str_list.c
+++ b/lib/datastruct/str_list.c
@@ -16,8 +16,6 @@
#include "lib.h"
#include "str_list.h"
-#include <ctype.h>
-
struct dm_list *str_list_create(struct dm_pool *mem)
{
struct dm_list *sl;
8 years, 6 months
master - cleanup: use display_lvname
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5ba219e87a37cd...
Commit: 5ba219e87a37cd18aa75971370254ed1fbdfde53
Parent: 04f76d9020dc1301540c949e0a0212e1ad44ff6d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 5 12:29:44 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:51 2015 +0100
cleanup: use display_lvname
---
lib/metadata/lv_manip.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index fbb5322..74b574a 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4018,13 +4018,12 @@ int lv_extend(struct logical_volume *lv,
dm_percent_t sync_percent = DM_PERCENT_INVALID;
if (!lv_is_active_locally(lv)) {
- log_error("%s/%s is not active locally."
- " Unable to get sync percent.",
- lv->vg->name, lv->name);
+ log_error("Unable to read sync percent while LV %s "
+ "is not locally active.", display_lvname(lv));
/* FIXME Support --force */
if (yes_no_prompt("Do full resync of extended "
- "portion of %s/%s? [y/n]: ",
- lv->vg->name, lv->name) == 'n') {
+ "portion of %s? [y/n]: ",
+ display_lvname(lv)) == 'n') {
r = 0;
goto_out;
}
@@ -4033,19 +4032,18 @@ int lv_extend(struct logical_volume *lv,
if (!(r = lv_mirror_percent(lv->vg->cmd, lv, 0,
&sync_percent, NULL))) {
- log_error("Failed to get sync percent for %s/%s",
- lv->vg->name, lv->name);
+ log_error("Failed to get sync percent for %s.",
+ display_lvname(lv));
goto out;
} else if (sync_percent == DM_PERCENT_100) {
log_verbose("Skipping initial resync for "
- "extended portion of %s/%s",
- lv->vg->name, lv->name);
+ "extended portion of %s",
+ display_lvname(lv));
init_mirror_in_sync(1);
lv->status |= LV_NOTSYNCED;
} else {
- log_error("%s/%s cannot be extended while"
- " it is recovering.",
- lv->vg->name, lv->name);
+ log_error("LV %s cannot be extended while it "
+ "is recovering.", display_lvname(lv));
r = 0;
goto out;
}
8 years, 6 months
master - cleanup: use NAME_LEN
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=04f76d9020dc13...
Commit: 04f76d9020dc1301540c949e0a0212e1ad44ff6d
Parent: 5c48ef993b372397716dc6f1cf81aec5b5ef2188
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 5 11:58:03 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:51 2015 +0100
cleanup: use NAME_LEN
Let's have instant check for max name len when creating
subLV name.
---
lib/metadata/lv_manip.c | 47 ++++++++++++++++++++++++++---------------------
1 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 48f470e..fbb5322 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -3718,8 +3718,7 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
uint32_t i;
uint64_t sub_lv_status = 0;
const char *layer_name;
- size_t len = strlen(lv->name) + 32;
- char img_name[len];
+ char img_name[NAME_LEN];
struct lv_segment *mapseg;
if (lv->le_count || !dm_list_empty(&lv->segments)) {
@@ -3745,7 +3744,8 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
if (!(mapseg = alloc_lv_segment(segtype, lv, 0, 0, lv->status,
stripe_size, NULL,
devices, 0, 0, region_size, 0, NULL))) {
- log_error("Failed to create mapping segment for %s", lv->name);
+ log_error("Failed to create mapping segment for %s.",
+ display_lvname(lv));
return 0;
}
@@ -3755,19 +3755,19 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
for (i = 0; i < devices; i++) {
/* Data LVs */
if (devices > 1) {
- if (dm_snprintf(img_name, len, "%s_%s_%u",
+ if (dm_snprintf(img_name, sizeof(img_name), "%s_%s_%u",
lv->name, layer_name, i) < 0)
- return_0;
+ goto_bad;
} else {
- if (dm_snprintf(img_name, len, "%s_%s",
+ if (dm_snprintf(img_name, sizeof(img_name), "%s_%s",
lv->name, layer_name) < 0)
- return_0;
+ goto_bad;
}
/* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
if (!(sub_lv = lv_create_empty(img_name, NULL,
- LVM_READ | LVM_WRITE,
- lv->alloc, lv->vg)))
+ LVM_READ | LVM_WRITE,
+ lv->alloc, lv->vg)))
return_0;
if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, sub_lv_status))
@@ -3775,24 +3775,29 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
/* Metadata LVs for raid */
if (segtype_is_raid(segtype)) {
- if (dm_snprintf(img_name, len, "%s_rmeta_%u", lv->name, i) < 0)
+ if (dm_snprintf(img_name, sizeof(img_name), "%s_rmeta_%u",
+ lv->name, i) < 0)
+ goto_bad;
+ /* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
+ if (!(sub_lv = lv_create_empty(img_name, NULL,
+ LVM_READ | LVM_WRITE,
+ lv->alloc, lv->vg)))
return_0;
- } else
- continue;
- /* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
- if (!(sub_lv = lv_create_empty(img_name, NULL,
- LVM_READ | LVM_WRITE,
- lv->alloc, lv->vg)))
- return_0;
-
- if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, RAID_META))
+ if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, RAID_META))
return_0;
+ }
}
dm_list_add(&lv->segments, &mapseg->list);
return 1;
+
+bad:
+ log_error("Failed to create sub LV name for LV %s.",
+ display_lvname(lv));
+
+ return 0;
}
static int _lv_extend_layered_lv(struct alloc_handle *ah,
@@ -3880,8 +3885,8 @@ static int _lv_extend_layered_lv(struct alloc_handle *ah,
return 0;
}
- log_verbose("Clearing metadata area of %s/%s",
- meta_lv->vg->name, meta_lv->name);
+ log_verbose("Clearing metadata area of %s",
+ display_lvname(meta_lv));
/*
* Rather than wiping meta_lv->size, we can simply
* wipe '1' to remove the superblock of any previous
8 years, 6 months
master - cleanup: use NAME_LEN buffer instead of alloca
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5c48ef993b3723...
Commit: 5c48ef993b372397716dc6f1cf81aec5b5ef2188
Parent: 2e04eee19213b3f498a4e8209cdcc14fcb7a0517
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 5 18:32:47 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:51 2015 +0100
cleanup: use NAME_LEN buffer instead of alloca
Drop alloca and use NAME_LEN size to get implicit check
for max len of LV name.
---
tools/lvconvert.c | 22 +++++++++-------------
1 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index c6cea0d..9fc064b 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -805,36 +805,32 @@ int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,
static int _insert_lvconvert_layer(struct cmd_context *cmd,
struct logical_volume *lv)
{
- char *format, *layer_name;
- size_t len;
+ char format[NAME_LEN], layer_name[NAME_LEN];
int i;
/*
- * We would like to give the same number for this layer
- * and the newly added mimage.
- * However, LV name of newly added mimage is determined *after*
+ * We would like to give the same number for this layer
+ * and the newly added mimage.
+ * However, LV name of newly added mimage is determined *after*
* the LV name of this layer is determined.
*
* So, use generate_lv_name() to generate mimage name first
* and take the number from it.
*/
- len = strlen(lv->name) + 32;
- if (!(format = alloca(len)) ||
- !(layer_name = alloca(len)) ||
- dm_snprintf(format, len, "%s_mimage_%%d", lv->name) < 0) {
- log_error("lvconvert: layer name allocation failed.");
+ if (dm_snprintf(format, sizeof(format), "%s_mimage_%%d", lv->name) < 0) {
+ log_error("lvconvert: layer name creation failed.");
return 0;
}
- if (!generate_lv_name(lv->vg, format, layer_name, len) ||
+ if (!generate_lv_name(lv->vg, format, layer_name, sizeof(layer_name)) ||
sscanf(layer_name, format, &i) != 1) {
log_error("lvconvert: layer name generation failed.");
return 0;
}
- if (dm_snprintf(layer_name, len, MIRROR_SYNC_LAYER "_%d", i) < 0) {
- log_error("layer name allocation failed.");
+ if (dm_snprintf(layer_name, sizeof(layer_name), MIRROR_SYNC_LAYER "_%d", i) < 0) {
+ log_error("layer name creation failed.");
return 0;
}
8 years, 6 months
master - cleanup: do not test alloca for NULL
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2e04eee19213b3...
Commit: 2e04eee19213b3f498a4e8209cdcc14fcb7a0517
Parent: c542c18d2af77f3114f22cf3d3845218285a5e62
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 5 18:32:32 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:51 2015 +0100
cleanup: do not test alloca for NULL
alloca() never returns NULL.
In case stack is out-of-range the behaviour is undefined.
---
lib/format_text/export.c | 6 +-----
lib/metadata/mirror.c | 20 ++++----------------
2 files changed, 5 insertions(+), 21 deletions(-)
diff --git a/lib/format_text/export.c b/lib/format_text/export.c
index ee9a9cf..8968f8c 100644
--- a/lib/format_text/export.c
+++ b/lib/format_text/export.c
@@ -341,11 +341,7 @@ static int _print_header(struct cmd_context *cmd, struct formatter *f,
outf(f, FORMAT_VERSION_FIELD " = %d", FORMAT_VERSION_VALUE);
outnl(f);
- if (!(buf = alloca(dm_escaped_len(desc)))) {
- log_error("temporary stack allocation for description"
- "string failed");
- return 0;
- }
+ buf = alloca(dm_escaped_len(desc));
outf(f, "description = \"%s\"", dm_escape_double_quotes(buf, desc));
outnl(f);
outf(f, "creation_host = \"%s\"\t# %s %s %s %s %s", _utsname.nodename,
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 8166e89..b69acf5 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -515,8 +515,7 @@ static int _merge_mirror_images(struct logical_volume *lv,
if (!addition)
return 1;
- if (!(img_lvs = alloca(sizeof(*img_lvs) * addition)))
- return_0;
+ img_lvs = alloca(sizeof(*img_lvs) * addition);
dm_list_iterate_items(lvl, mimages)
img_lvs[i++] = lvl->lv;
@@ -1461,11 +1460,7 @@ static int _create_mimage_lvs(struct alloc_handle *ah,
size_t len;
len = strlen(lv->name) + 32;
- if (!(img_name = alloca(len))) {
- log_error("img_name allocation failed. "
- "Remove new LV and retry.");
- return 0;
- }
+ img_name = alloca(len);
if (dm_snprintf(img_name, len, "%s_mimage_%%d", lv->name) < 0) {
log_error("img_name allocation failed. "
@@ -1861,10 +1856,7 @@ static struct logical_volume *_create_mirror_log(struct logical_volume *lv,
size_t len;
len = strlen(lv_name) + 32;
- if (!(log_name = alloca(len))) {
- log_error("log_name allocation failed.");
- return NULL;
- }
+ log_name = alloca(len); /* alloca never fails */
if (dm_snprintf(log_name, len, "%s%s", lv_name, suffix) < 0) {
log_error("log_name allocation failed.");
@@ -1903,11 +1895,7 @@ static int _form_mirror(struct cmd_context *cmd, struct alloc_handle *ah,
/*
* create mirror image LVs
*/
- if (!(img_lvs = alloca(sizeof(*img_lvs) * mirrors))) {
- log_error("img_lvs allocation failed. "
- "Remove new LV and retry.");
- return 0;
- }
+ img_lvs = alloca(sizeof(*img_lvs) * mirrors);
if (!_create_mimage_lvs(ah, mirrors, stripes, stripe_size, lv, img_lvs, log))
return_0;
8 years, 6 months
master - cleanup: drop unneded assign
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c542c18d2af77f...
Commit: c542c18d2af77f3114f22cf3d3845218285a5e62
Parent: 07046e994fc10882cac20d16666368a6de18a528
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:49:57 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:51 2015 +0100
cleanup: drop unneded assign
Coverity doesn't really like to see subcommand being assigned NULL,
so drop it.
---
tools/dmsetup.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index d6c0ad7..15bff64 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -6132,7 +6132,7 @@ int main(int argc, char **argv)
int ret = 1, r;
const char *dev_dir;
const struct command *cmd;
- const char *subcommand = NULL;
+ const char *subcommand;
int multiple_devices;
(void) setlocale(LC_ALL, "");
@@ -6228,7 +6228,7 @@ unknown:
subcommand = argv[0];
argc--, argv++;
} else
- subcommand = (char *) "";
+ subcommand = "";
if (_switches[COLS_ARG] && !_report_init(cmd, subcommand))
goto_out;
8 years, 6 months
master - alloc: use own mem pool for alloc_handle
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=07046e994fc108...
Commit: 07046e994fc10882cac20d16666368a6de18a528
Parent: 0c380c316c51920db5b5721863cb1b55bfa9acf1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Nov 4 14:54:07 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:22:49 2015 +0100
alloc: use own mem pool for alloc_handle
Keep alloc_handle's data in a single mempool and do not
spread them into vgmem pool.
---
WHATS_NEW | 1 +
lib/metadata/lv_manip.c | 19 ++++++++++---------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 00b7ee1..7dc5a45 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.135 -
====================================
+ Use local memory pool for whole alloc_handle manipulation.
Add missing pointer validation after dm_get_next_target().
Do not deref NULL pointer in debug message for _match_pv_tags().
Drop unneeded stat() call when checking for sysfs file.
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index c9cc6b5..48f470e 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -3138,7 +3138,6 @@ int lv_add_virtual_segment(struct logical_volume *lv, uint64_t status,
* If log_area_count > 1 it is always mirrored (not striped).
*/
static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
- struct dm_pool *mem,
const struct segment_type *segtype,
alloc_policy_t alloc, int approx_alloc,
uint32_t existing_extents,
@@ -3150,6 +3149,7 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
uint32_t region_size,
struct dm_list *parallel_areas)
{
+ struct dm_pool *mem;
struct alloc_handle *ah;
uint32_t s, area_count, alloc_count, parity_count, total_extents;
size_t size = 0;
@@ -3199,21 +3199,23 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
size += sizeof(ah->alloced_areas[0]) * alloc_count;
+ if (!(mem = dm_pool_create("allocation", 1024))) {
+ log_error("allocation pool creation failed");
+ return NULL;
+ }
+
if (!(ah = dm_pool_zalloc(mem, size))) {
log_error("allocation handle allocation failed");
+ dm_pool_destroy(mem);
return NULL;
}
ah->cmd = cmd;
+ ah->mem = mem;
if (segtype_is_virtual(segtype))
return ah;
- if (!(ah->mem = dm_pool_create("allocation", 1024))) {
- log_error("allocation pool creation failed");
- return NULL;
- }
-
ah->area_count = area_count;
ah->parity_count = parity_count;
ah->region_size = region_size;
@@ -3314,8 +3316,7 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
void alloc_destroy(struct alloc_handle *ah)
{
- if (ah->mem)
- dm_pool_destroy(ah->mem);
+ dm_pool_destroy(ah->mem);
}
/*
@@ -3356,7 +3357,7 @@ struct alloc_handle *allocate_extents(struct volume_group *vg,
if (alloc >= ALLOC_INHERIT)
alloc = vg->alloc;
- if (!(ah = _alloc_init(vg->cmd, vg->vgmem, segtype, alloc, approx_alloc,
+ if (!(ah = _alloc_init(vg->cmd, segtype, alloc, approx_alloc,
lv ? lv->le_count : 0, extents, mirrors, stripes, log_count,
vg->extent_size, region_size,
parallel_areas)))
8 years, 6 months
master - cleanup: relocate error capture
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0c380c316c5192...
Commit: 0c380c316c51920db5b5721863cb1b55bfa9acf1
Parent: 67b4761bc3c53ee67a1fbe33f41757a6563db5cb
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Nov 4 14:53:25 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:21:09 2015 +0100
cleanup: relocate error capture
Capture internal error before allocation anything.
---
lib/metadata/lv_manip.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index e23a8b9..c9cc6b5 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -3165,6 +3165,12 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
else
area_count = stripes;
+ if (!segtype_is_virtual(segtype) &&
+ !(area_count + metadata_area_count)) {
+ log_error(INTERNAL_ERROR "_alloc_init called for non-virtual segment with no disk space.");
+ return NULL;
+ }
+
size = sizeof(*ah);
/*
@@ -3203,11 +3209,6 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
if (segtype_is_virtual(segtype))
return ah;
- if (!(area_count + metadata_area_count)) {
- log_error(INTERNAL_ERROR "_alloc_init called for non-virtual segment with no disk space.");
- return NULL;
- }
-
if (!(ah->mem = dm_pool_create("allocation", 1024))) {
log_error("allocation pool creation failed");
return NULL;
8 years, 6 months
master - toollib: add missing check for lvmcache_init()
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=67b4761bc3c53e...
Commit: 67b4761bc3c53ee67a1fbe33f41757a6563db5cb
Parent: 164d7e72bfd6fa0564e195d0c0fdf64893566ad6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:47:21 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:20 2015 +0100
toollib: add missing check for lvmcache_init()
Coverity notices lvmcache_init() may fail so check and
error out in case of failure.
---
tools/toollib.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 42ac71a..a52252e 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -3181,7 +3181,11 @@ int process_each_pv(struct cmd_context *cmd,
log_verbose("Some PVs were not found in first search, retrying.");
lvmcache_destroy(cmd, 0, 0);
- lvmcache_init();
+ if (!lvmcache_init()) {
+ log_error("Failed to initalize lvm cache.");
+ ret_max = ECMD_FAILED;
+ goto out;
+ }
lvmcache_seed_infos_from_lvmetad(cmd);
ret = _process_pvs_in_vgs(cmd, read_flags, &all_vgnameids, &all_devices,
8 years, 6 months
master - devmanager: validate target params
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=164d7e72bfd6fa...
Commit: 164d7e72bfd6fa0564e195d0c0fdf64893566ad6
Parent: 4f8f8fcb52d1d1f2a46468aa6bb4a8da11804c5b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 9 09:27:18 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 9 10:19:20 2015 +0100
devmanager: validate target params
Coverity: ensure we do not read through NULL pointers for
target_type and params.
---
WHATS_NEW | 1 +
lib/activate/dev_manager.c | 12 ++++++------
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 7930631..00b7ee1 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.135 -
====================================
+ Add missing pointer validation after dm_get_next_target().
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.
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 6ec9d22..0b24f86 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -498,14 +498,14 @@ static int _ignore_suspended_snapshot_component(struct device *dev)
do {
next = dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
- if (!strcmp(target_type, "snapshot")) {
- if (sscanf(params, "%d:%d %d:%d", &major1, &minor1, &major2, &minor2) != 4) {
+ if (!target_type || !strcmp(target_type, "snapshot")) {
+ if (!params || sscanf(params, "%d:%d %d:%d", &major1, &minor1, &major2, &minor2) != 4) {
log_error("Incorrect snapshot table found");
goto_out;
}
r = r || _device_is_suspended(major1, minor1) || _device_is_suspended(major2, minor2);
} else if (!strcmp(target_type, "snapshot-origin")) {
- if (sscanf(params, "%d:%d", &major1, &minor1) != 2) {
+ if (!params || sscanf(params, "%d:%d", &major1, &minor1) != 2) {
log_error("Incorrect snapshot-origin table found");
goto_out;
}
@@ -545,7 +545,7 @@ static int _ignore_unusable_thins(struct device *dev)
goto out;
}
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
- if (sscanf(params, "%d:%d", &minor, &major) != 2) {
+ if (!params || sscanf(params, "%d:%d", &minor, &major) != 2) {
log_error("Failed to get thin-pool major:minor for thin device %d:%d.",
(int)MAJOR(dev->dev), (int)MINOR(dev->dev));
goto out;
@@ -1678,12 +1678,12 @@ int dev_manager_thin_device_id(struct dev_manager *dm,
goto out;
}
- if (strcmp(target_type, "thin")) {
+ if (!target_type || strcmp(target_type, "thin")) {
log_error("Unexpected target type %s found for thin %s.", target_type, lv->name);
goto out;
}
- if (sscanf(params, "%*u:%*u %u", device_id) != 1) {
+ if (!params || sscanf(params, "%*u:%*u %u", device_id) != 1) {
log_error("Cannot parse table like parameters %s for %s.", params, lv->name);
goto out;
}
8 years, 6 months