Linksys SRW224G4 WebGUI is Broken
Last week I bought a Linksys SRW224G4 switch for my rack. It seemed like a nice piece of kit, and I got it for a good price.
The first part of the setup went well enough, using the telnet interface. As I wanted to get my head around all the options the switch offered, I thought I would try WebView. The image below shows what I got with Firefox, on Konqueror is worse.
The Linksys helpdesk wasn’t very helpful. Most calls weren’t returned when promised and the scripts didn’t seem to deal with this issue. In the end I was told to use Internet Explorer. I knew it worked with IE6 running under WINE, but that isn’t the point. This is a modern piece of network infrastructure - it should work on any browser, especially one which has almost 30% market share in Oceania.
For the last 5 years or so I have used a fair bit of Linksys kit, as I find they build high quality network equipment. Another big plus for Linksys in my book has been their support for FOSS and hacking - especially the WRT54GL and NSLU2. Now I am not so sure.
Instead of just waiting for the ticket to make its way through the internal bureaucracy of Linksys so that eventually a developer investigates the bug, I thought I would lay it all out here for them. So here we go.
The error in the error console is:
Error: tbl.firstChild.firstChild has no properties
Source File: http://192.168.XXX.YYY/js/tabs.js
Line: 24
The code is question is as follows (line 24 is highlighted):
[...]
function setTabset(ths) {
[...]
var tbl = ths.parentNode.parentNode.parentNode.parentNode;
subLinks = document.getElementsByName("lnk");
for (var i = 0; i < subLinks.length; i++) {
if (subLinks[i] == ths) {
if (subLinks[i].innerHTML == "LogOut") {
var msg = "Are you sure you want to Log Off?";
if (!confirm(msg)) {
return;
}
}
curTd = tbl.firstChild.firstChild.childNodes[tab].style;
[...]
The argument passed to the function above is a HTML element with an id attribute of ’tab_0’. This element exists, it is the “Setup” tab in the screenshot above. Lets walk through the relevant bits of the code.
var tbl = ths.parentNode.parentNode.parentNode.parentNode; `
This steps 4 levels up the DOM tree, from the tab_0 element (the whole webgui is rendered using tables). This works fine. Now tbl references a table element with an id of ‘Table2’.
Now we skip down to the line which has the error.
curTd = tbl.firstChild.firstChild.childNodes[tab].style;
This attempts to step down 3 levels from the top of the table to one of the tabs and retrieve the style object for that element. Here are the steps
tbl
- the table itselftbl.firstChild
- the first child node of the table - a text nodetbl.firstChild.firstChild
- a non existent node as the parent is a text node with no children
Why does this work on IE, but not Firefox/Konqueror and other FOSS browsers? I haven’t checked for konq, but I know that the gecko engine (used by Firefox, SeaMonkey, IceWeasel etc etc), the DOM parser is whitespace sensitive. Every bit of text (whitespace or otherwise) is considered to be a text node. This is W3C compliant, there is even a bug report for it - see bug #26179 on mozilla’s bugzilla.
This is pretty easy to fix, I haven’t tested the code below for this case, but something like it usually works.
/* * Find the first child which is a html element */
function findFirstChild(elm) {
if (!elm.childNodes.length) {
return;
}
var children = elm.childNodes.length;
for (var i = 0; i <= children; ++i) {
if (elm.childNodes[i].nodeType == 1) {
return elm.childNodes[i];
}
}
return;
}
[...]
function setTabset(ths) {
[...]
curTd = findFirstChild(findFirstChild(tbl)).childNodes[tab].style;
[...]
I hope that Linksys sets their QA team on the SRW224G4 firmware with Firefox to find the other bugs like this one. Unless Linksys fixes there gecko based browser support rather promptly, I won’t be recommending (or using) their products in future.
Special thanks to the Firebug and DOM Inspector extensions which made this so much easier to trace.
Linksys will be emailed a link to this post and my ticket number. I will keep people posted on how things progress.
Update 2020: This bug was never fixed. I have long since replaced the buggy switch. These days I use Ubiquiti UniFi kit where ever possible.