datapath: Check device name length more carefully in create_dp().
authorBen Pfaff <blp@nicira.com>
Tue, 27 Apr 2010 17:45:28 +0000 (10:45 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 27 Apr 2010 17:45:28 +0000 (10:45 -0700)
I don't see any value in silently truncating device names.  Doing so will
sow confusion in userspace.  This commit makes too-long device names
return ENAMETOOLONG.

datapath/datapath.c

index e9590f75fdde32b61b12b4563cca123bc85f4596..4f74795e8c05ff4b6f21923a18cbbeaff3e72281 100644 (file)
@@ -202,10 +202,14 @@ static int create_dp(int dp_idx, const char __user *devnamep)
        int i;
 
        if (devnamep) {
-               err = -EFAULT;
-               if (strncpy_from_user(devname, devnamep, IFNAMSIZ) < 0)
+               int retval = strncpy_from_user(devname, devnamep, IFNAMSIZ);
+               if (retval < 0) {
+                       err = -EFAULT;
                        goto err;
-               devname[IFNAMSIZ - 1] = '\0';
+               } else if (retval >= IFNAMSIZ) {
+                       err = -ENAMETOOLONG;
+                       goto err;
+               }
        } else {
                snprintf(devname, sizeof devname, "of%d", dp_idx);
        }