Skip to content

Commit ebb3e9f

Browse files
Merge pull request #1172 from vojtechtrefny/master_lvm-dbus-input-validation
lvm-dbus: Validate device/object ID parameters for NULL and empty string
2 parents 7da09fc + 55a8070 commit ebb3e9f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/plugins/lvm/lvm-dbus.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ static gchar* get_object_path (const gchar *obj_id, GError **error) {
438438
GVariant *ret = NULL;
439439
gchar *obj_path = NULL;
440440

441+
if (!obj_id || g_strcmp0 (obj_id, "") == 0) {
442+
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_NOEXIST,
443+
"Invalid LVM ID specified");
444+
return NULL;
445+
}
446+
441447
args = g_variant_new ("(s)", obj_id);
442448
/* consumes (frees) the 'args' parameter */
443449
ret = g_dbus_connection_call_sync (bus, LVM_BUS_NAME, MANAGER_OBJ, MANAGER_INTF,
@@ -955,6 +961,12 @@ static GVariant* get_pv_properties (const gchar *pv_name, GError **error) {
955961
gchar *obj_id = NULL;
956962
GVariant *ret = NULL;
957963

964+
if (!pv_name || g_strcmp0 (pv_name, "") == 0) {
965+
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_NOEXIST,
966+
"Invalid LVM ID specified");
967+
return NULL;
968+
}
969+
958970
if (!g_str_has_prefix (pv_name, "/dev/")) {
959971
obj_id = g_strdup_printf ("/dev/%s", pv_name);
960972
ret = get_lvm_object_properties (obj_id, PV_INTF, error);
@@ -1523,6 +1535,12 @@ gboolean bd_lvm_pvcreate (const gchar *device, guint64 data_alignment, guint64 m
15231535
GVariant *params = NULL;
15241536
GVariant *extra_params = NULL;
15251537

1538+
if (!device || g_strcmp0 (device, "") == 0) {
1539+
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_NOEXIST,
1540+
"Invalid LVM ID specified");
1541+
return FALSE;
1542+
}
1543+
15261544
if (data_alignment != 0 || metadata_size != 0) {
15271545
g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY);
15281546
if (data_alignment != 0) {
@@ -1586,6 +1604,12 @@ gboolean bd_lvm_pvremove (const gchar *device, const BDExtraArg **extra, GError
15861604
GError *l_error = NULL;
15871605
gboolean ret = FALSE;
15881606

1607+
if (!device || g_strcmp0 (device, "") == 0) {
1608+
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_NOEXIST,
1609+
"Invalid LVM ID specified");
1610+
return FALSE;
1611+
}
1612+
15891613
if (access (device, F_OK) != 0) {
15901614
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_NOEXIST,
15911615
"The device '%s' doesn't exist", device);

tests/lvm_dbus_tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def setUpClass(cls):
4646
def test_plugin_version(self):
4747
self.assertEqual(BlockDev.get_plugin_soname(BlockDev.Plugin.LVM), "libbd_lvm-dbus.so.3")
4848

49+
@tag_test(TestTags.NOSTORAGE)
50+
def test_empty_device(self):
51+
"""Verify that passing an empty device string returns a proper error"""
52+
53+
with self.assertRaisesRegex(GLib.GError, "Invalid LVM ID specified"):
54+
BlockDev.lvm_pvcreate("", 0, 0, None)
55+
56+
with self.assertRaisesRegex(GLib.GError, "Invalid LVM ID specified"):
57+
BlockDev.lvm_pvresize("", 0, None)
58+
59+
with self.assertRaisesRegex(GLib.GError, "Invalid LVM ID specified"):
60+
BlockDev.lvm_vgremove("", None)
61+
4962
@tag_test(TestTags.NOSTORAGE)
5063
def test_tech_available(self):
5164
"""Verify that checking lvm dbus availability by technology works as expected"""

0 commit comments

Comments
 (0)