[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torbutton/master] Bug #9224: about:tor fails if > 1 SOCKS listener



commit 2167f0cbd7a0591c1d5e94b97bd2f10111f8137b
Author: Kathy Brade <brade@xxxxxxxxxxxxxxxxx>
Date:   Fri Sep 20 11:01:39 2013 -0400

    Bug #9224: about:tor fails if > 1 SOCKS listener
    
    Correctly parse GETINFO response when more than one
    SOCKS listener is configured.
---
 src/chrome/content/torbutton.js |   61 ++++++++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 23 deletions(-)

diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index ed87a0c..97156c8 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1637,6 +1637,8 @@ function torbutton_do_tor_check()
 
 function torbutton_local_tor_check()
 {
+  let didLogError = false;
+
   let proxyType = m_tb_prefs.getIntPref("network.proxy.type");
   if (0 == proxyType)
     return false;
@@ -1650,10 +1652,13 @@ function torbutton_local_tor_check()
 
   function logUnexpectedResponse()
   {
-    torbutton_log(5, "unexpected tor response: " + resp);
+    if (!didLogError) {
+      didLogError = true;
+      torbutton_log(5, "unexpected tor response: " + resp);
+    }
   }
 
-  // Sample response: net/listeners/socks="127.0.0.1:9150"
+  // 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 + '=')) {
@@ -1661,31 +1666,41 @@ function torbutton_local_tor_check()
     return false;
   }
 
-  // Remove double quotes if present.
-  resp = resp.substr(kCmdArg.length + 1);
-  let len = resp.length;
-  if ((len > 2) && ('"' == resp.charAt(0)) && ('"' == resp.charAt(len - 1)))
-    resp = resp.substring(1, len - 1);
+  // 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 addrArray = resp.substr(kCmdArg.length + 1).split(' ');
+  let foundSocksListener = false;
+  for (let i = 0; !foundSocksListener && (i < addrArray.length); ++i)
+  {
+    var addr = addrArray[i];
 
-  let tokens = resp.split(':');
-  if (tokens.length < 2) {
-    logUnexpectedResponse();
-    return false;
-  }
+    // 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);
 
-  let torSocksAddr = tokens[0];
-  let torSocksPort = parseInt(tokens[1], 10);
-  if ((torSocksAddr.length < 1) || isNaN(torSocksPort)) {
-    logUnexpectedResponse();
-    return false;
+    // Check against the configured proxy.
+    let tokens = addr.split(':');
+    if (tokens.length < 2)
+      logUnexpectedResponse();
+    else
+    {
+      let torSocksAddr = tokens[0];
+      let torSocksPort = parseInt(tokens[1], 10);
+      if ((torSocksAddr.length < 1) || isNaN(torSocksPort))
+        logUnexpectedResponse();
+      else
+      {
+        torbutton_log(2, "Tor socks listener: " + torSocksAddr + ':'
+                         + torSocksPort);
+        foundSocksListener = ((socksAddr == torSocksAddr) &&
+                              (socksPort == torSocksPort));
+      }
+    }
   }
 
-  torbutton_log(2, "Tor socks listener: " + torSocksAddr + ':' + torSocksPort);
-
-  let socksAddr = m_tb_prefs.getCharPref("network.proxy.socks");
-  let socksPort = m_tb_prefs.getIntPref("network.proxy.socks_port");
-
-  return ((socksAddr == torSocksAddr) && (socksPort == torSocksPort));
+  return foundSocksListener;
 } // torbutton_local_tor_check
 
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits