luci-mod-network: add stricter wireless interface name validation
authorGlenn Washburn <development@efficientek.com>
Thu, 2 Mar 2023 05:39:48 +0000 (23:39 -0600)
committerJo-Philipp Wich <jo@mein.io>
Wed, 15 Mar 2023 22:56:59 +0000 (23:56 +0100)
Linux wireless interface names have the following restrictions:

 * It must not be an empty string
 * It must not be '.' or '..'
 * It must not contain any /, : or space character ( , \t, \n, ...)
 * It must be less than 16 chars
 * It likely must not contain any % either

Fixes: 8673aef8db ("luci-mod-network: remove uciname validation from wireless interface")
Signed-off-by: Glenn Washburn <development@efficientek.com>
[reword validation error messages, remove extended description text as it would be
 shown as part of the validation errors]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/validation.js
modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js

index 6dddf964fb93d21fb07518cdd52fcb6d7ffc4b50..b7a3a140e4c54b1a4f23dd78af8d547c9204a9d6 100644 (file)
@@ -426,6 +426,15 @@ var ValidatorFactory = baseclass.extend({
                        return this.assert(this.value.match(/^[a-zA-Z0-9_]+$/), _('valid UCI identifier'));
                },
 
+               netdevname: function() {
+                       var v = this.value;
+
+                       if (v == '.' || v == '..')
+                               return this.assert(false, _('valid network device name, not "." or ".."'));
+
+                       return this.assert(v.match(/^[^:/%\s]{1,15}$/), _('valid network device name between 1 and 15 characters not containing ":", "/", "%" or spaces'));
+               },
+
                range: function(min, max) {
                        var val = this.factory.parseDecimal(this.value);
                        return this.assert(val >= +min && val <= +max, _('value between %f and %f').format(min, max));
index a2b0c84ce211c50183a3790e1193790e14e395ee..6b1bd262fb7afe2e2b6f7e42fa90b3c84da6eb91 100644 (file)
@@ -1152,7 +1152,7 @@ return view.extend({
 
                                        o = ss.taboption('advanced', form.Value, 'ifname', _('Interface name'), _('Override default interface name'));
                                        o.optional = true;
-                                       o.datatype = 'maxlength(15)';
+                                       o.datatype = 'netdevname';
                                        o.placeholder = radioNet.getIfname();
                                        if (/^radio\d+\.network/.test(o.placeholder))
                                                o.placeholder = '';