[tor-commits] [obfsproxy/master] Fix some copy-and-paste errors in network.c and some resource-reuse errors in tester.py.in

nickm at torproject.org nickm at torproject.org
Fri Sep 9 17:08:57 UTC 2011


commit 3d5e463cb108e31b9c575cbfbe1917a92ef5c0f7
Author: Zack Weinberg <zackw at panix.com>
Date:   Wed Jul 27 10:51:13 2011 -0700

    Fix some copy-and-paste errors in network.c and some resource-reuse errors in tester.py.in
---
 src/network.c         |   11 ++++++++---
 src/test/tester.py.in |   45 ++++++++++++++++++++++++++++++---------------
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/src/network.c b/src/network.c
index f7a94d3..f05c5b8 100644
--- a/src/network.c
+++ b/src/network.c
@@ -409,8 +409,8 @@ conn_free(conn_t *conn)
     socks_state_free(conn->socks_state);
   if (conn->upstream)
     bufferevent_free(conn->upstream);
-  if (conn->upstream)
-    bufferevent_free(conn->upstream);
+  if (conn->downstream)
+    bufferevent_free(conn->downstream);
 
   memset(conn, 0x99, sizeof(conn_t));
   free(conn);
@@ -611,6 +611,11 @@ error_cb(struct bufferevent *bev, short what, void *arg)
   obfs_assert(what & (BEV_EVENT_EOF|BEV_EVENT_ERROR|BEV_EVENT_TIMEOUT));
   obfs_assert(!(what & BEV_EVENT_CONNECTED));
 
+  /* If we get EAGAIN or EINPROGRESS here, something has gone horribly
+     wrong. */
+  obfs_assert(EVUTIL_SOCKET_ERROR() != EAGAIN &&
+              EVUTIL_SOCKET_ERROR() != EINPROGRESS);
+
   log_warn("Got error: %s",
            evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
   error_or_eof(arg, bev);
@@ -731,7 +736,7 @@ pending_socks_cb(struct bufferevent *bev, short what, void *arg)
                       downstream_read_cb, NULL, error_cb, conn);
     bufferevent_enable(conn->upstream, EV_READ|EV_WRITE);
     if (evbuffer_get_length(bufferevent_get_input(conn->upstream)) != 0)
-      downstream_read_cb(bev, conn->upstream);
+      upstream_read_cb(conn->upstream, conn);
     return;
   }
 
diff --git a/src/test/tester.py.in b/src/test/tester.py.in
index b0602ed..104026c 100644
--- a/src/test/tester.py.in
+++ b/src/test/tester.py.in
@@ -147,9 +147,6 @@ class SocksTest(object):
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE)
 
-        self.input_chan = connect_with_retry(("127.0.0.1", ENTRY_PORT))
-        self.input_chan.settimeout(1.0)
-
     def tearDown(self):
         if self.obfs_server.returncode is None:
             self.obfs_server.terminate()
@@ -193,14 +190,17 @@ class SocksTest(object):
     def socksTest(self, sequence):
         sending = True
         good = True
+        input_chan = connect_with_retry(("127.0.0.1", ENTRY_PORT))
+        input_chan.settimeout(1.0)
+
         for msg in sequence:
             if msg is False:
-                self.input_chan.shutdown(socket.SHUT_WR)
+                input_chan.shutdown(socket.SHUT_WR)
                 # Expect either a clean closedown or a connection reset
                 # at this point.
                 got = ""
                 try:
-                    got = self.input_chan.recv(4096)
+                    got = input_chan.recv(4096)
                 except socket.error, e:
                     if e.errno != errno.ECONNRESET: raise
                 self.assertEqual(got, "")
@@ -213,33 +213,36 @@ class SocksTest(object):
             else:
                 raise TypeError("incomprehensible msg: " + repr(msg))
             if sending:
-                self.input_chan.sendall(exp)
+                input_chan.sendall(exp)
             else:
                 got = ""
                 try:
-                    got = self.input_chan.recv(4096)
+                    got = input_chan.recv(4096)
                 except socket.error, e:
                     if e.errno != errno.ECONNRESET: raise
                 self.assertEqual(got, exp)
         if good:
-            self.input_chan.sendall(TEST_FILE)
-            self.input_chan.shutdown(socket.SHUT_WR)
+            input_chan.sendall(TEST_FILE)
+            input_chan.shutdown(socket.SHUT_WR)
             try:
                 output = self.output_reader.get()
             except Queue.Empty:
                 output = ""
-            self.assertEqual(output, TEST_FILE)
 
-        self.input_chan.close()
+        input_chan.close()
         self.checkSubprocesses()
 
+        if good:
+            self.assertEqual(output, TEST_FILE)
+
+
     def test_illformed(self):
         # ill-formed socks message - server should drop connection
         self.socksTest([ "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n"
                          "Connection: close\r\n\r\n",
                          False ])
 
-    def test_socks4_unsupported_methods(self):
+    def test_socks4_unsupported_method_1(self):
         # SOCKS4 bind request - should fail, presently just drops connection
         self.socksTest([ ( (4, 2, SERVER_PORT, 127, 0, 0, 1, 0), "!BBH5B" ),
                          False ])
@@ -249,23 +252,35 @@ class SocksTest(object):
         self.socksTest([ ( (4, 1, SERVER_PORT, 127, 0, 0, 1, 0), "!BBH5B" ),
                          ( (0, 90, SERVER_PORT, 127, 0, 0, 1), "!BBH4B" ) ])
 
-    def test_socks5_bad_handshakes(self):
+    def test_socks5_bad_handshake_1(self):
         self.socksTest([ "\x05", False ])
+
+    def test_socks5_bad_handshake_2(self):
         self.socksTest([ "\x05\x00", False ])
+
+    def test_socks5_bad_handshake_3(self):
         self.socksTest([ "\x05\x01\x01", "\x05\xFF", False ])
+
+    def test_socks5_bad_handshake_4(self):
         self.socksTest([ "\x05\x01\x080", "\x05\xFF", False ])
+
+    def test_socks5_bad_handshake_5(self):
         self.socksTest([ "\x05\x02\x01\x02", "\x05\xFF", False ])
 
-    def test_socks5_bad_requests(self):
+    def test_socks5_bad_request_1(self):
         self.socksTest([ "\x05\x01\x00", "\x05\x00", "\x05\x00",
                          "\x05\x07\x00", False ])
+
+    def test_socks5_bad_request_2(self):
         self.socksTest([ "\x05\x02\x00\x01", "\x05\x00", "\x05\x00",
                          "\x05\x07\x00", False ])
 
-    def test_socks5_unsupported_methods(self):
+    def test_socks5_unsupported_method_1(self):
         self.socksTest([ "\x05\x01\x00", "\x05\x00",
                          ( (5, 2, 0, 1, 127, 0, 0, 1, SERVER_PORT), "!8BH" ),
                          "\x05\x07\x00", False ])
+
+    def test_socks5_unsupported_method_2(self):
         self.socksTest([ "\x05\x01\x00", "\x05\x00",
                          ( (5, 3, 0, 1, 127, 0, 0, 1, SERVER_PORT), "!8BH" ),
                          "\x05\x07\x00", False ])





More information about the tor-commits mailing list