main - cov: ensure fid is not null
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e1287c3b711d9d77221...
Commit: e1287c3b711d9d77221b0114dbb5ebd84c09ca48
Parent: 04fd55a0c9e721e8d73f067f886736377ba879e3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 15:11:23 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: ensure fid is not null
---
tools/pvscan.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 83f3f3983..df38e1758 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -1232,7 +1232,8 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
if (!vg) {
log_print("pvscan[%d] PV %s has no VG metadata.", getpid(), dev_name(dev));
- fmt->ops->destroy_instance(fid);
+ if (fid)
+ fmt->ops->destroy_instance(fid);
goto online;
}
3 years
main - cov: ensure segtype is not null
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=04fd55a0c9e721e8d73...
Commit: 04fd55a0c9e721e8d73f067f886736377ba879e3
Parent: cdcd8011d05a0cb7c6a07800dae2a0f99da8a5ee
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 15:11:08 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: ensure segtype is not null
---
tools/lvconvert.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index b50074294..ab6892105 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1373,7 +1373,8 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
if (!*lp->type_str) {
lp->type_str = SEG_TYPE_NAME_RAID1;
- lp->segtype = get_segtype_from_string(lv->vg->cmd, SEG_TYPE_NAME_RAID1);
+ if (!(lp->segtype = get_segtype_from_string(lv->vg->cmd, SEG_TYPE_NAME_RAID1)))
+ return_0;
type_enforced = 1;
}
}
3 years
main - cov: add explicit check for external not being null
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cdcd8011d05a0cb7c6a...
Commit: cdcd8011d05a0cb7c6a07800dae2a0f99da8a5ee
Parent: d388b36da236e66dd42e59d7b5c9d596d6de1961
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Apr 23 22:47:18 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: add explicit check for external not being null
Although the code should never evaluate for null external
add explict check for analyzer.
---
tools/vgsplit.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 778e63d47..8a785bdbd 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -341,8 +341,9 @@ static int _move_thins(struct volume_group *vg_from,
if ((_lv_is_in_vg(vg_to, data_lv) ||
_lv_is_in_vg(vg_to, seg->external_lv))) {
- if (_lv_is_in_vg(vg_from, seg->external_lv) ||
- _lv_is_in_vg(vg_from, data_lv)) {
+ if (seg->external_lv &&
+ (_lv_is_in_vg(vg_from, seg->external_lv) ||
+ _lv_is_in_vg(vg_from, data_lv))) {
log_error("Can't split external origin %s "
"and pool %s between two Volume Groups.",
display_lvname(seg->external_lv),
3 years
main - cov: daemonize avoid leak of FD on error path
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d388b36da236e66dd42...
Commit: d388b36da236e66dd42e59d7b5c9d596d6de1961
Parent: d95b26fae0bdab7d306f0dff1d9328a697e041f3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 15:05:31 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: daemonize avoid leak of FD on error path
Use our common patter for reopening FDs to /dev/null
that avoids leaking FD on error path.
---
libdm/dm-tools/dmfilemapd.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/libdm/dm-tools/dmfilemapd.c b/libdm/dm-tools/dmfilemapd.c
index e15f0015f..2a86810ed 100644
--- a/libdm/dm-tools/dmfilemapd.c
+++ b/libdm/dm-tools/dmfilemapd.c
@@ -653,18 +653,21 @@ static int _daemonise(struct filemap_monitor *fm)
}
if (!_verbose) {
- if (close(STDIN_FILENO))
- _early_log("Error closing stdin");
- if (close(STDOUT_FILENO))
- _early_log("Error closing stdout");
- if (close(STDERR_FILENO))
- _early_log("Error closing stderr");
- if ((open("/dev/null", O_RDONLY) < 0) ||
- (open("/dev/null", O_WRONLY) < 0) ||
- (open("/dev/null", O_WRONLY) < 0)) {
- _early_log("Error opening stdio streams.");
+ if ((fd = open("/dev/null", O_RDWR)) == -1) {
+ _early_log("Error opening /dev/null.");
return 0;
}
+
+ if ((dup2(fd, STDIN_FILENO) == -1) ||
+ (dup2(fd, STDOUT_FILENO) == -1) ||
+ (dup2(fd, STDERR_FILENO) == -1)) {
+ if (fd > STDERR_FILENO)
+ (void) close(fd);
+ _early_log("Error redirecting stdin/out/err to null.");
+ return 0;
+ }
+ if (fd > STDERR_FILENO)
+ (void) close(fd);
}
/* TODO: Use libdaemon/server/daemon-server.c _daemonise() */
for (fd = (int) sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; fd--) {
3 years
main - cov: check setup_devices return code
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d95b26fae0bdab7d306...
Commit: d95b26fae0bdab7d306f0dff1d9328a697e041f3
Parent: ece80cd0fbce92d2ce248913fceffbf15e9d37f0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 12:34:16 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: check setup_devices return code
---
tools/pvck.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/pvck.c b/tools/pvck.c
index 6bc1c091f..74663ec43 100644
--- a/tools/pvck.c
+++ b/tools/pvck.c
@@ -3187,8 +3187,8 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
if (argc == 1)
setup_device(cmd, argv[0]);
- else
- setup_devices(cmd);
+ else if (!setup_devices(cmd))
+ return ECMD_FAILED;
for (i = 0; i < argc; i++) {
pv_name = argv[i];
3 years
main - cov: avoid passed invalid dummy structure
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ece80cd0fbce92d2ce2...
Commit: ece80cd0fbce92d2ce248913fceffbf15e9d37f0
Parent: bf461b99c6d26e550835b77eaffe2204cbc9bed3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 12:32:35 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: avoid passed invalid dummy structure
Altough this dummy structure should not be using pe_size anywhere,
make analyzer happier and avoid PV structures with zero pe_size.
---
tools/toollib.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/toollib.c b/tools/toollib.c
index 5ce2ff346..8f9ea1e6b 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -4000,6 +4000,7 @@ static int _process_duplicate_pvs(struct cmd_context *cmd,
int ret = 0;
struct physical_volume dummy_pv = {
+ .pe_size = 1,
.tags = DM_LIST_HEAD_INIT(dummy_pv.tags),
.segments= DM_LIST_HEAD_INIT(dummy_pv.segments),
};
3 years
main - cov: check label_read_pvid return value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bf461b99c6d26e55083...
Commit: bf461b99c6d26e550835b77eaffe2204cbc9bed3
Parent: 7e135868374601020920094f135d678c688d0950
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 12:31:49 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: check label_read_pvid return value
Command can early exit when function returns 0.
---
tools/lvmdevices.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
index b67db7464..c6cb1fcff 100644
--- a/tools/lvmdevices.c
+++ b/tools/lvmdevices.c
@@ -181,7 +181,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
continue;
dev = du->dev;
- label_read_pvid(dev);
+ if (!label_read_pvid(dev))
+ continue;
/*
* label_read_pvid has read the first 4K of the device
@@ -283,7 +284,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* (it's ok if the device is not a PV and has no PVID)
*/
label_scan_setup_bcache();
- label_read_pvid(dev);
+ if (!label_read_pvid(dev))
+ goto_bad;
/*
* Allow filtered devices to be added to devices_file, but
3 years
main - cov: check _insert_dev return value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7e13586837460102092...
Commit: 7e135868374601020920094f135d678c688d0950
Parent: d7237ca63a1497fc06a975639331ea7869b02c1a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 12:30:26 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: check _insert_dev return value
Although we try later to validate device was inserted,
we can validate return value and early-exit.
---
lib/device/dev-cache.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index aa93b5758..dddf84e4d 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1510,7 +1510,8 @@ struct device *dev_cache_get(struct cmd_context *cmd, const char *name, struct d
* for st_rdev.
*/
if (!dev) {
- _insert_dev(name, st.st_rdev);
+ if (!_insert_dev(name, st.st_rdev))
+ return_NULL;
/* Get the struct dev that was just added. */
dev = (struct device *) dm_hash_lookup(_cache.names, name);
3 years
main - cov: add checks to prevent NULL dereference
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d7237ca63a1497fc06a...
Commit: d7237ca63a1497fc06a975639331ea7869b02c1a
Parent: 3d96203e21be7fcea783afaa94e10295696a4533
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 15:08:04 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 23:00:55 2021 +0200
cov: add checks to prevent NULL dereference
---
lib/device/device_id.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 1a9705f04..9fd22692c 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -523,7 +523,7 @@ int device_ids_read(struct cmd_context *cmd)
_copy_idline_str(line, _devices_file_systemid, sizeof(_devices_file_systemid));
log_debug("read devices file systemid %s", _devices_file_systemid);
if ((!cmd->system_id && _devices_file_systemid[0]) ||
- strcmp(cmd->system_id, _devices_file_systemid)) {
+ (cmd->system_id && strcmp(cmd->system_id, _devices_file_systemid))) {
log_warn("WARNING: ignoring devices file with wrong system id %s vs local %s.",
_devices_file_systemid[0] ? _devices_file_systemid : "none", cmd->system_id ?: "none");
free_dus(&cmd->use_devices);
@@ -1077,7 +1077,8 @@ id_done:
if (du_devid && (du_devid != du_dev)) {
log_warn("WARNING: device %s (%s) and %s (%s) have duplicate device ID.",
dev_name(dev), id->idname,
- du_pvid->dev ? dev_name(du_pvid->dev) : "none", du_pvid->idname);
+ (du_pvid && du_pvid->dev) ? dev_name(du_pvid->dev) : "none",
+ du_pvid ? du_pvid->idname : "");
}
if (du_pvid && (du_pvid != du_dev)) {
3 years
main - cov: avoid leak when repeating options
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3d96203e21be7fcea78...
Commit: 3d96203e21be7fcea783afaa94e10295696a4533
Parent: 7e77e250a9249f6b7c9bc63b88de393c02ef6a61
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Apr 22 17:53:45 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Apr 23 22:59:25 2021 +0200
cov: avoid leak when repeating options
Do not leak previous buffer, when option is set more then once.
---
daemons/lvmlockd/lvmlockctl.c | 4 ++++
tools/pvck.c | 1 +
2 files changed, 5 insertions(+)
diff --git a/daemons/lvmlockd/lvmlockctl.c b/daemons/lvmlockd/lvmlockctl.c
index 350e78e9a..32da99c6d 100644
--- a/daemons/lvmlockd/lvmlockctl.c
+++ b/daemons/lvmlockd/lvmlockctl.c
@@ -987,18 +987,22 @@ static int read_options(int argc, char *argv[])
break;
case 'k':
kill_vg = 1;
+ free(arg_vg_name);
arg_vg_name = strdup(optarg);
break;
case 'r':
drop_vg = 1;
+ free(arg_vg_name);
arg_vg_name = strdup(optarg);
break;
case 'E':
gl_enable = 1;
+ free(arg_vg_name);
arg_vg_name = strdup(optarg);
break;
case 'D':
gl_disable = 1;
+ free(arg_vg_name);
arg_vg_name = strdup(optarg);
break;
case 'S':
diff --git a/tools/pvck.c b/tools/pvck.c
index 2af34dc57..6bc1c091f 100644
--- a/tools/pvck.c
+++ b/tools/pvck.c
@@ -1774,6 +1774,7 @@ static int _get_one_setting(struct cmd_context *cmd, struct settings *set, char
}
if (!strncmp(key, "backup_file", strlen("backup_file"))) {
+ free(set->backup_file);
if ((set->backup_file = strdup(val)))
return 1;
return 0;
3 years