]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Bulletproof connection_ap_handshake_attach_chosen_circuit
authorNick Mathewson <nickm@torproject.org>
Thu, 24 Mar 2005 06:05:14 +0000 (06:05 +0000)
committerNick Mathewson <nickm@torproject.org>
Thu, 24 Mar 2005 06:05:14 +0000 (06:05 +0000)
svn:r3855

src/or/circuituse.c

index 669d96e94e7f27c8ea01f13ca04e2f010c3faa9e..e9c20f59a8592a4bcc14f047ae38e918f54f9c01 100644 (file)
@@ -979,8 +979,8 @@ consider_recording_trackhost(connection_t *conn, circuit_t *circ) {
 }
 
 /** Attempt to attach the connection <b>conn</b> to <b>circ</b>, and
- * send a begin or resolve cell as appropriate.  Return values for
- * connection_ap_handshake_attach_chosen_circuit. */
+ * send a begin or resolve cell as appropriate.  Return values are as
+ * for connection_ap_handshake_attach_circuit. */
 int
 connection_ap_handshake_attach_chosen_circuit(connection_t *conn,
                                               circuit_t *circ)
@@ -992,6 +992,9 @@ connection_ap_handshake_attach_chosen_circuit(connection_t *conn,
   tor_assert(conn->socks_request);
   tor_assert(circ);
 
+  if (circ->state != CIRCUIT_STATE_OPEN)
+    return 0;
+
   conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
 
   if (!circ->timestamp_dirty)
@@ -1001,9 +1004,11 @@ connection_ap_handshake_attach_chosen_circuit(connection_t *conn,
   tor_assert(conn->socks_request);
   if (conn->socks_request->command == SOCKS_COMMAND_CONNECT) {
     consider_recording_trackhost(conn, circ);
-    connection_ap_handshake_send_begin(conn, circ);
+    if (connection_ap_handshake_send_begin(conn, circ)<0)
+      return -1;
   } else {
-    connection_ap_handshake_send_resolve(conn, circ);
+    if (connection_ap_handshake_send_resolve(conn, circ)<0)
+      return -1;
   }
 
   return 1;