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

[or-cvs] Change from inet_ntoa to a threadproof tor_inet_ntoa.



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv20997/src/or

Modified Files:
	buffers.c circuitbuild.c config.c connection.c 
	connection_edge.c connection_or.c cpuworker.c rendservice.c 
	router.c routerparse.c test.c 
Log Message:
Change from inet_ntoa to a threadproof tor_inet_ntoa.

Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/buffers.c,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- buffers.c	3 Jan 2005 23:19:15 -0000	1.125
+++ buffers.c	22 Feb 2005 08:18:34 -0000	1.126
@@ -448,7 +448,7 @@
  */
 int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
   unsigned char len;
-  char *tmpbuf=NULL;
+  char tmpbuf[INET_NTOA_BUF_LEN];
   uint32_t destip;
   enum {socks4, socks4a} socks4_prot = socks4a;
   char *next, *startaddr;
@@ -505,7 +505,7 @@
 
           destip = ntohl(*(uint32_t*)(buf->mem+4));
           in.s_addr = htonl(destip);
-          tmpbuf = inet_ntoa(in);
+          tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
           if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
             log_fn(LOG_WARN,"socks5 IP takes %d bytes, which doesn't fit in %d. Rejecting.",
                    (int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
@@ -565,7 +565,7 @@
       if (destip >> 8) {
         log_fn(LOG_DEBUG,"socks4: destip not in form 0.0.0.x.");
         in.s_addr = htonl(destip);
-        tmpbuf = inet_ntoa(in);
+        tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
         if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
           log_fn(LOG_WARN,"socks4 addr (%d bytes) too long. Rejecting.",
                  (int)strlen(tmpbuf));

Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- circuitbuild.c	16 Feb 2005 02:06:54 -0000	1.82
+++ circuitbuild.c	22 Feb 2005 08:18:34 -0000	1.83
@@ -503,9 +503,11 @@
      * router twice in a row in the path. I think that's ok.
      */
     struct in_addr in;
+    char tmpbuf[INET_NTOA_BUF_LEN];
     in.s_addr = htonl(circ->n_addr);
+    tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
     log_fn(LOG_INFO,"Next router (%s:%d) not connected. Connecting.",
-           inet_ntoa(in), circ->n_port);
+           tmpbuf, circ->n_port);
 
     memcpy(circ->onionskin, onionskin, ONIONSKIN_CHALLENGE_LEN);
     circ->state = CIRCUIT_STATE_OR_WAIT;

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.314
retrieving revision 1.315
diff -u -d -r1.314 -r1.315
--- config.c	22 Feb 2005 06:38:39 -0000	1.314
+++ config.c	22 Feb 2005 08:18:35 -0000	1.315
@@ -928,6 +928,7 @@
   struct hostent *rent;
   char hostname[256];
   int explicit_ip=1;
+  char tmpbuf[INET_NTOA_BUF_LEN];
 
   tor_assert(addr);
 
@@ -957,14 +958,15 @@
     memcpy(&in.s_addr, rent->h_addr, rent->h_length);
   }
 
+  tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
   if (!explicit_ip && is_internal_IP(htonl(in.s_addr))) {
     log_fn(LOG_WARN,"Address '%s' resolves to private IP '%s'. "
            "Please set the Address config option to be the IP you want to use.",
-           hostname, inet_ntoa(in));
+           hostname, tmpbuf);
     return -1;
   }
 
-  log_fn(LOG_DEBUG, "Resolved Address to %s.", inet_ntoa(in));
+  log_fn(LOG_DEBUG, "Resolved Address to %s.", tmpbuf);
   *addr = ntohl(in.s_addr);
   return 0;
 }

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.327
retrieving revision 1.328
diff -u -d -r1.327 -r1.328
--- connection.c	22 Feb 2005 03:02:33 -0000	1.327
+++ connection.c	22 Feb 2005 08:18:35 -0000	1.328
@@ -462,6 +462,7 @@
   struct sockaddr_in remote;
   /* length of the remote address. Must be an int, since accept() needs that. */
   int remotelen = sizeof(struct sockaddr_in);
+  char tmpbuf[INET_NTOA_BUF_LEN];
 
   news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
   if (!SOCKET_IS_POLLABLE(news)) {
@@ -495,8 +496,9 @@
   if (new_type == CONN_TYPE_AP) {
     /* check sockspolicy to see if we should accept it */
     if (socks_policy_permits_address(ntohl(remote.sin_addr.s_addr)) == 0) {
+      tor_inet_ntoa(&remote.sin_addr, tmpbuf, sizeof(tmpbuf));
       log_fn(LOG_NOTICE,"Denying socks connection from untrusted address %s.",
-             inet_ntoa(remote.sin_addr));
+             tmpbuf);
       tor_close_socket(news);
       return 0;
     }
@@ -504,8 +506,9 @@
   if (new_type == CONN_TYPE_DIR) {
     /* check dirpolicy to see if we should accept it */
     if (dir_policy_permits_address(ntohl(remote.sin_addr.s_addr)) == 0) {
+      tor_inet_ntoa(&remote.sin_addr, tmpbuf, sizeof(tmpbuf));
       log_fn(LOG_NOTICE,"Denying dir connection from address %s.",
-             inet_ntoa(remote.sin_addr));
+             tmpbuf);
       tor_close_socket(news);
       return 0;
     }
@@ -514,7 +517,10 @@
   newconn = connection_new(new_type);
   newconn->s = news;
 
-  newconn->address = tor_strdup(inet_ntoa(remote.sin_addr)); /* remember the remote address */
+  /* remember the remote address */
+  newconn->address = tor_malloc(INET_NTOA_BUF_LEN);
+  tor_inet_ntoa(&remote.sin_addr, newconn->address, INET_NTOA_BUF_LEN);
+
   newconn->addr = ntohl(remote.sin_addr.s_addr);
   newconn->port = ntohs(remote.sin_port);
 

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -d -r1.280 -r1.281
--- connection_edge.c	22 Feb 2005 00:55:50 -0000	1.280
+++ connection_edge.c	22 Feb 2005 08:18:35 -0000	1.281
@@ -482,13 +482,16 @@
 void client_dns_set_addressmap(const char *address, uint32_t val)
 {
   struct in_addr in;
+  char *addr;
 
   tor_assert(address); tor_assert(val);
 
   if (tor_inet_aton(address, &in))
     return; /* don't set an addressmap back to ourselves! */
   in.s_addr = htonl(val);
-  addressmap_register(address, strdup(inet_ntoa(in)),
+  addr = tor_malloc(INET_NTOA_BUF_LEN);
+  tor_inet_ntoa(&in,addr,INET_NTOA_BUF_LEN);
+  addressmap_register(address, addr,
                       time(NULL) + MAX_DNS_ENTRY_AGE);
 }
 
@@ -1109,11 +1112,13 @@
           (r->port_min <= port) && (port <= r->port_max)) {
         struct in_addr in;
         if (r->is_redirect) {
+          char tmpbuf[INET_NTOA_BUF_LEN];
           addr = r->addr_dest;
           port = r->port_dest;
           in.s_addr = htonl(addr);
+          tor_inet_ntoa(&in, tmpbuf, sizeof(tmpbuf));
           log_fn(LOG_DEBUG, "Redirecting connection from %s:%d to %s:%d",
-                 conn->address, conn->port, inet_ntoa(in), port);
+                 conn->address, conn->port, tmpbuf, port);
         }
         break;
       }

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_or.c,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- connection_or.c	3 Feb 2005 22:58:22 -0000	1.158
+++ connection_or.c	22 Feb 2005 08:18:35 -0000	1.159
@@ -157,7 +157,9 @@
   }
   tor_free(conn->address);
   in.s_addr = htonl(addr);
-  conn->address = tor_strdup(inet_ntoa(in));
+
+  conn->address = tor_malloc(INET_NTOA_BUF_LEN);
+  tor_inet_ntoa(&in,conn->address,INET_NTOA_BUF_LEN);
 }
 
 void

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/cpuworker.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- cpuworker.c	28 Jan 2005 10:00:29 -0000	1.66
+++ cpuworker.c	22 Feb 2005 08:18:35 -0000	1.67
@@ -67,13 +67,15 @@
  */
 static void tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t *circ_id) {
   struct in_addr in;
+  char addrbuf[INET_NTOA_BUF_LEN];
 
   *addr    = *(const uint32_t *)tag;
   *port    = *(const uint16_t *)(tag+4);
   *circ_id = *(const uint16_t *)(tag+6);
 
   in.s_addr = htonl(*addr);
-  log_fn(LOG_DEBUG,"onion was from %s:%d, circ_id %d.", inet_ntoa(in), *port, *circ_id);
+  tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
+  log_fn(LOG_DEBUG,"onion was from %s:%d, circ_id %d.", addrbuf, *port, *circ_id);
 }
 
 /** Called when the onion key has changed and we need to spawn new

Index: rendservice.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendservice.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- rendservice.c	10 Feb 2005 23:18:39 -0000	1.116
+++ rendservice.c	22 Feb 2005 08:18:35 -0000	1.117
@@ -113,10 +113,12 @@
     smartlist_add(rend_service_list, service);
     log_fn(LOG_DEBUG,"Configuring service with directory %s",service->directory);
     for (i = 0; i < smartlist_len(service->ports); ++i) {
+      char addrbuf[INET_NTOA_BUF_LEN];
       p = smartlist_get(service->ports, i);
       addr.s_addr = htonl(p->real_address);
+      tor_inet_ntoa(&addr, addrbuf, sizeof(addrbuf));
       log_fn(LOG_DEBUG,"Service maps port %d to %s:%d",
-             p->virtual_port, inet_ntoa(addr), p->real_port);
+             p->virtual_port, addrbuf, p->real_port);
     }
   }
 }

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- router.c	11 Feb 2005 07:56:10 -0000	1.146
+++ router.c	22 Feb 2005 08:18:35 -0000	1.147
@@ -541,6 +541,7 @@
   struct in_addr in;
   int hibernating = we_are_hibernating();
   or_options_t *options = get_options();
+  char addrbuf[INET_NTOA_BUF_LEN];
 
   if (!desc_is_dirty && !force)
     return 0;
@@ -552,7 +553,8 @@
 
   ri = tor_malloc_zero(sizeof(routerinfo_t));
   in.s_addr = htonl(addr);
-  ri->address = tor_strdup(inet_ntoa(in));
+  tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
+  ri->address = tor_strdup(addrbuf);
   ri->nickname = tor_strdup(options->Nickname);
   ri->addr = addr;
   ri->or_port = options->ORPort;
@@ -628,6 +630,7 @@
   char published[32];
   char fingerprint[FINGERPRINT_LEN+1];
   struct in_addr in;
+  char addrbuf[INET_NTOA_BUF_LEN];
   size_t onion_pkeylen, identity_pkeylen;
   size_t written;
   int result=0;
@@ -729,16 +732,18 @@
   for (tmpe=router->exit_policy; tmpe; tmpe=tmpe->next) {
     in.s_addr = htonl(tmpe->addr);
     /* Write: "accept 1.2.3.4" */
+    tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
     result = tor_snprintf(s+written, maxlen-written, "%s %s",
         tmpe->policy_type == ADDR_POLICY_ACCEPT ? "accept" : "reject",
-        tmpe->msk == 0 ? "*" : inet_ntoa(in));
+        tmpe->msk == 0 ? "*" : addrbuf);
     if (result < 0)
       return -1;
     written += result;
     if (tmpe->msk != 0xFFFFFFFFu && tmpe->msk != 0) {
       /* Write "/255.255.0.0" */
+      tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
       in.s_addr = htonl(tmpe->msk);
-      result = tor_snprintf(s+written, maxlen-written, "/%s", inet_ntoa(in));
+      result = tor_snprintf(s+written, maxlen-written, "/%s", addrbuf);
       if (result<0)
         return -1;
       written += result;

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- routerparse.c	29 Jan 2005 11:48:37 -0000	1.99
+++ routerparse.c	22 Feb 2005 08:18:35 -0000	1.100
@@ -1054,8 +1054,10 @@
 router_parse_addr_policy(directory_token_t *tok) {
 
   addr_policy_t *newe;
-  struct in_addr in;
-  char *arg, *address;
+//  struct in_addr in;
+  char *arg;
+//  char *address;
+//  char buf[INET_NTOA_BUF_LEN];
 
   tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
 
@@ -1076,13 +1078,14 @@
                                 &newe->prt_min, &newe->prt_max))
     goto policy_read_failed;
 
-  in.s_addr = htonl(newe->addr);
-  address = tor_strdup(inet_ntoa(in));
+//  in.s_addr = htonl(newe->addr);
+//  tor_inet_ntoa(&in, buf, sizeof(buf));
+//  address = tor_strdup(buf);
 //  in.s_addr = htonl(newe->msk);
 //  log_fn(LOG_DEBUG,"%s %s/%s:%d-%d",
 //         newe->policy_type == ADDR_POLICY_REJECT ? "reject" : "accept",
 //         address, inet_ntoa(in), newe->prt_min, newe->prt_max);
-  tor_free(address);
+//  tor_free(address);
 
   return newe;
 

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.168
retrieving revision 1.169
diff -u -d -r1.168 -r1.169
--- test.c	22 Feb 2005 03:01:31 -0000	1.168
+++ test.c	22 Feb 2005 08:18:36 -0000	1.169
@@ -791,6 +791,14 @@
   test_assert(strcmpend("abcdef", "dee")>0);
   test_assert(strcmpend("ab", "abb")<0);
 
+  {
+    char tmpbuf[INET_NTOA_BUF_LEN];
+    struct in_addr in;
+    tor_inet_aton("18.244.0.188",&in);
+    tor_inet_ntoa(&in, tmpbuf, sizeof(tmpbuf));
+    test_streq(tmpbuf, "18.244.0.188");
+  }
+
   /* XXXX test older functions. */
   smartlist_free(sl);
 }