Skip to content
Snippets Groups Projects
Commit f1932e73 authored by Kathleen Brade's avatar Kathleen Brade
Browse files

Bug 19733: GETINFO response parser doesn't handle AF_UNIX entries.

When performing the local Tor check (which compares the configured
Firefox SOCKS proxy to the one reported by GETINFO net/listeners/socks),
correctly handle UNIX domain sockets as well as IPv6 addresses.
parent 1b41636c
Branches
No related tags found
No related merge requests found
// Bug 1506 P0-P5: This is the main Torbutton overlay file. Much needs to be
// preserved here, but in an ideal world, most of this code should perhaps be
// moved into an XPCOM service, and much can also be tossed. See also
// individual 1506 comments for details.
......@@ -1528,13 +1527,21 @@ function torbutton_local_tor_check()
{
if (!didLogError) {
didLogError = true;
torbutton_log(5, "unexpected tor response: " + resp);
torbutton_log(5, "Local Tor check: unexpected GETINFO response: " + resp);
}
}
function removeBrackets(aStr)
{
// Remove enclosing square brackets if present.
if (aStr.startsWith('[') && aStr.endsWith(']'))
return aStr.substr(1, aStr.length - 2);
return aStr;
}
// Sample response: net/listeners/socks="127.0.0.1:9149" "127.0.0.1:9150"
// First, check for command argument prefix.
resp = resp.toLowerCase();
if (0 != resp.indexOf(kCmdArg + '=')) {
logUnexpectedResponse();
return false;
......@@ -1543,29 +1550,62 @@ function torbutton_local_tor_check()
// Retrieve configured proxy settings and check each listener against them.
let socksAddr = m_tb_prefs.getCharPref("network.proxy.socks");
let socksPort = m_tb_prefs.getIntPref("network.proxy.socks_port");
let socketPath;
if (socksAddr && (socksAddr.substr(0, 5) == "file:")) {
// Ensure that the Unix domain socket path is fully qualified by
// converting the network.proxy.socks preference value (file:path) to
// a file URI object and then back to a path.
try {
let socksFile = Cc['@mozilla.org/file/local;1']
.createInstance(Ci.nsILocalFile);
socksFile.initWithPath(socksAddr.substr(5));
let ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
let fileURI = ioService.newFileURI(socksFile);
socketPath = fileURI.path;
} catch (e) {
torbutton_log(5, "Local Tor check: Unix domain socket error: " + e);
return false;
}
} else {
socksAddr = removeBrackets(socksAddr);
}
let addrArray = resp.substr(kCmdArg.length + 1).split(' ');
let foundSocksListener = false;
for (let i = 0; !foundSocksListener && (i < addrArray.length); ++i)
{
var addr = addrArray[i];
for (let i = 0; !foundSocksListener && (i < addrArray.length); ++i) {
let addr = addrArray[i];
// Remove double quotes if present.
let len = addr.length;
if ((len > 2) && ('"' == addr.charAt(0)) && ('"' == addr.charAt(len - 1)))
addr = addr.substring(1, len - 1);
// Check against the configured proxy.
let tokens = addr.split(':');
if (tokens.length < 2)
if (addr.startsWith("unix:")) {
if (!socketPath)
continue;
// Check against the configured UNIX domain socket proxy. We expect to
// find "/path" in socksAddr and we ignore socksPort. This matches what
// is proposed for Firefox; see:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1211567
let path = addr.substring(5);
torbutton_log(2, "Tor socks listener (socket): " + path);
foundSocksListener = (socketPath == path);
} else if (!socketPath) {
// Check against the configured TCP proxy. We expect addr:port where addr
// may be an IPv6 address; that is, it may contain colon characters.
// Also, we remove enclosing square brackets before comparing addresses
// because tor requires them but Firefox does not.
let idx = addr.lastIndexOf(':');
if (idx < 0) {
logUnexpectedResponse();
else
{
let torSocksAddr = tokens[0];
let torSocksPort = parseInt(tokens[1], 10);
if ((torSocksAddr.length < 1) || isNaN(torSocksPort))
} else {
let torSocksAddr = removeBrackets(addr.substring(0, idx));
let torSocksPort = parseInt(addr.substring(idx + 1), 10);
if ((torSocksAddr.length < 1) || isNaN(torSocksPort)) {
logUnexpectedResponse();
else
{
} else {
torbutton_log(2, "Tor socks listener: " + torSocksAddr + ':'
+ torSocksPort);
foundSocksListener = ((socksAddr == torSocksAddr) &&
......@@ -1573,6 +1613,7 @@ function torbutton_local_tor_check()
}
}
}
}
return foundSocksListener;
} // torbutton_local_tor_check
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment