1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

devmanager: validate target params

Coverity: ensure we do not read through NULL pointers for
target_type and params.
This commit is contained in:
Zdenek Kabelac 2015-11-09 09:27:18 +01:00
parent 4f8f8fcb52
commit 164d7e72bf
2 changed files with 7 additions and 6 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.135 - 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(). Do not deref NULL pointer in debug message for _match_pv_tags().
Drop unneeded stat() call when checking for sysfs file. Drop unneeded stat() call when checking for sysfs file.
Fix memory leak on error path of failing thin-pool percentage check. Fix memory leak on error path of failing thin-pool percentage check.

View File

@ -498,14 +498,14 @@ static int _ignore_suspended_snapshot_component(struct device *dev)
do { do {
next = dm_get_next_target(dmt, next, &start, &length, &target_type, &params); next = dm_get_next_target(dmt, next, &start, &length, &target_type, &params);
if (!strcmp(target_type, "snapshot")) { if (!target_type || !strcmp(target_type, "snapshot")) {
if (sscanf(params, "%d:%d %d:%d", &major1, &minor1, &major2, &minor2) != 4) { if (!params || sscanf(params, "%d:%d %d:%d", &major1, &minor1, &major2, &minor2) != 4) {
log_error("Incorrect snapshot table found"); log_error("Incorrect snapshot table found");
goto_out; goto_out;
} }
r = r || _device_is_suspended(major1, minor1) || _device_is_suspended(major2, minor2); r = r || _device_is_suspended(major1, minor1) || _device_is_suspended(major2, minor2);
} else if (!strcmp(target_type, "snapshot-origin")) { } 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"); log_error("Incorrect snapshot-origin table found");
goto_out; goto_out;
} }
@ -545,7 +545,7 @@ static int _ignore_unusable_thins(struct device *dev)
goto out; goto out;
} }
dm_get_next_target(dmt, next, &start, &length, &target_type, &params); dm_get_next_target(dmt, next, &start, &length, &target_type, &params);
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.", log_error("Failed to get thin-pool major:minor for thin device %d:%d.",
(int)MAJOR(dev->dev), (int)MINOR(dev->dev)); (int)MAJOR(dev->dev), (int)MINOR(dev->dev));
goto out; goto out;
@ -1678,12 +1678,12 @@ int dev_manager_thin_device_id(struct dev_manager *dm,
goto out; 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); log_error("Unexpected target type %s found for thin %s.", target_type, lv->name);
goto out; 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); log_error("Cannot parse table like parameters %s for %s.", params, lv->name);
goto out; goto out;
} }