[or-cvs] Populate address field of listeners with an actually sane v...

Nick Mathewson nickm at seul.org
Thu Jul 14 22:56:20 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv12257/src/or

Modified Files:
	connection.c 
Log Message:
Populate address field of listeners with an actually sane value.

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.383
retrieving revision 1.384
diff -u -d -r1.383 -r1.384
--- connection.c	14 Jul 2005 08:43:19 -0000	1.383
+++ connection.c	14 Jul 2005 22:56:17 -0000	1.384
@@ -454,6 +454,7 @@
 connection_create_listener(const char *bindaddress, uint16_t bindport, int type)
 {
   struct sockaddr_in bindaddr; /* where to bind */
+  char *address = NULL;
   connection_t *conn;
   uint16_t usePort;
   uint32_t addr;
@@ -463,7 +464,7 @@
 #endif
 
   memset(&bindaddr,0,sizeof(struct sockaddr_in));
-  if (parse_addr_port(bindaddress, NULL, &addr, &usePort)<0) {
+  if (parse_addr_port(bindaddress, &address, &addr, &usePort)<0) {
     log_fn(LOG_WARN, "Error parsing/resolving BindAddress %s",bindaddress);
     return -1;
   }
@@ -477,11 +478,11 @@
   s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
   if (s < 0) {
     log_fn(LOG_WARN,"Socket creation failed.");
-    return -1;
+    goto err;
   } else if (!SOCKET_IS_POLLABLE(s)) {
     log_fn(LOG_WARN,"Too many connections; can't create pollable listener.");
     tor_close_socket(s);
-    return -1;
+    goto err;
   }
 
 #ifndef MS_WINDOWS
@@ -495,26 +496,27 @@
   if (bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) {
     log_fn(LOG_WARN,"Could not bind to port %u: %s",usePort,
            tor_socket_strerror(tor_socket_errno(s)));
-    return -1;
+    goto err;
   }
 
   if (listen(s,SOMAXCONN) < 0) {
     log_fn(LOG_WARN,"Could not listen on port %u: %s",usePort,
            tor_socket_strerror(tor_socket_errno(s)));
-    return -1;
+    goto err;
   }
 
   set_socket_nonblocking(s);
 
   conn = connection_new(type);
   conn->s = s;
-  conn->address = tor_strdup(bindaddress);
+  conn->address = address;
+  address = NULL;
   conn->port = usePort;
 
   if (connection_add(conn) < 0) { /* no space, forget it */
     log_fn(LOG_WARN,"connection_add failed. Giving up.");
     connection_free(conn);
-    return -1;
+    goto err;
   }
 
   log_fn(LOG_DEBUG,"%s listening on port %u.",conn_type_to_string(type), usePort);
@@ -523,6 +525,10 @@
   connection_start_reading(conn);
 
   return 0;
+
+ err:
+  tor_free(address);
+  return -1;
 }
 
 /** Do basic sanity checking on a newly received socket. Return 0



More information about the tor-commits mailing list