]> sourceware.org Git - lvm2.git/commitdiff
Add checks for device names in dmsetup and show proper error messages.
authorprajnoha <prajnoha>
Wed, 7 Jan 2009 12:17:40 +0000 (12:17 +0000)
committerprajnoha <prajnoha>
Wed, 7 Jan 2009 12:17:40 +0000 (12:17 +0000)
Checks added for DM device names to allow only names < DM_NAME_LEN,
otherwise a part of lengthy name would be silently ignored and could
cause confusion while using dmsetup. Also, the name should not contain
'/' character, if it is used in context of creating a new device
or renaming the existing one (because we do not consider full path
to devices, they do not exist in filesystem yet) and appropriate error
messages are shown.

WHATS_NEW_DM
libdm/ioctl/libdm-iface.c
libdm/libdm-common.c

index cec8696907d76cab69478ccee25dce7c5693c922..ee9b53d88d677b9047d2061571cdb2a441844da3 100644 (file)
@@ -1,5 +1,6 @@
 Version 1.02.30 -
 ====================================
+  Add checks for device names in dmsetup and show proper error messages.
   Replace _dm_snprintf with EMIT_PARAMS macro for creating target lines
 
 Version 1.02.29 - 10th November 2008
index 05b6894078950c687cbe3efefd9dba27497ea92a..0c5a7304787db0434a7936c1f6111a6b4725ac28 100644 (file)
@@ -1018,6 +1018,16 @@ int dm_task_suppress_identical_reload(struct dm_task *dmt)
 
 int dm_task_set_newname(struct dm_task *dmt, const char *newname)
 {
+       if (strchr(newname, '/')) {
+               log_error("Name \"%s\" invalid. It contains \"/\".", newname);
+               return 0;
+       }
+
+       if (strlen(newname) >= DM_NAME_LEN) {
+               log_error("Name \"%s\" too long", newname);
+               return 0;
+       }
+
        if (!(dmt->newname = dm_strdup(newname))) {
                log_error("dm_task_set_newname: strdup(%s) failed", newname);
                return 0;
index 26fc0437d4ed979bcf023268e742106d9527a090..bbb46f51c76303bacd835eca02337979b47b3a8d 100644 (file)
@@ -143,18 +143,27 @@ int dm_task_set_name(struct dm_task *dmt, const char *name)
         * as its last component.
         */
        if ((pos = strrchr(name, '/'))) {
+               if (dmt->type == DM_DEVICE_CREATE) {
+                       log_error("Name \"%s\" invalid. It contains \"/\".", name);
+                       return 0;
+               }
+
                snprintf(path, sizeof(path), "%s/%s", _dm_dir, pos + 1);
 
                if (stat(name, &st1) || stat(path, &st2) ||
                    !(st1.st_dev == st2.st_dev)) {
-                       log_error("dm_task_set_name: Device %s not found",
-                                 name);
+                       log_error("Device %s not found", name);
                        return 0;
                }
 
                name = pos + 1;
        }
 
+       if (strlen(name) >= DM_NAME_LEN) {
+               log_error("Name \"%s\" too long", name);
+               return 0;
+       }
+
        if (!(dmt->dev_name = dm_strdup(name))) {
                log_error("dm_task_set_name: strdup(%s) failed", name);
                return 0;
This page took 0.04068 seconds and 5 git commands to generate.