[or-cvs] Use strlcpy, not strncpy

Nick Mathewson nickm at seul.org
Wed Oct 27 06:03:30 UTC 2004


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

Modified Files:
	dirserv.c dns.c 
Log Message:
Use strlcpy, not strncpy

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- dirserv.c	27 Oct 2004 05:53:07 -0000	1.101
+++ dirserv.c	27 Oct 2004 06:03:28 -0000	1.102
@@ -386,9 +386,7 @@
   ent->nickname = tor_strdup(ri->nickname);
   ent->published = ri->published_on;
   ent->desc_len = desc_len;
-  ent->descriptor = tor_malloc(desc_len+1);
-  strncpy(ent->descriptor, start, desc_len);
-  ent->descriptor[desc_len] = '\0';
+  ent->descriptor = tor_strndup(start,desc_len);
   ent->router = ri;
   /* XXX008 is ent->verified useful/used for anything? */
   ent->verified = verified; /* XXXX008 support other possibilities. */

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- dns.c	16 Oct 2004 22:14:51 -0000	1.113
+++ dns.c	27 Oct 2004 06:03:28 -0000	1.114
@@ -201,8 +201,7 @@
   purge_expired_resolves(now);
 
   /* now check the tree to see if 'address' is already there. */
-  strncpy(search.address, exitconn->address, MAX_ADDRESSLEN);
-  search.address[MAX_ADDRESSLEN-1] = 0;
+  strlcpy(search.address, exitconn->address, sizeof(search.address));
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
   if(resolve) { /* already there */
     switch(resolve->state) {
@@ -237,8 +236,7 @@
   resolve = tor_malloc_zero(sizeof(struct cached_resolve));
   resolve->state = CACHE_STATE_PENDING;
   resolve->expire = now + MAX_DNS_ENTRY_AGE;
-  strncpy(resolve->address, exitconn->address, MAX_ADDRESSLEN);
-  resolve->address[MAX_ADDRESSLEN-1] = 0;
+  strlcpy(resolve->address, exitconn->address, sizeof(resolve->address));
 
   /* add us to the pending list */
   pending_connection = tor_malloc_zero(sizeof(struct pending_connection_t));
@@ -306,8 +304,7 @@
   tor_assert(conn->type == CONN_TYPE_EXIT);
   tor_assert(conn->state == EXIT_CONN_STATE_RESOLVING);
 
-  strncpy(search.address, conn->address, MAX_ADDRESSLEN);
-  search.address[MAX_ADDRESSLEN-1] = 0;
+  strlcpy(search.address, conn->address, sizeof(search.address));
 
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
   if(!resolve) {
@@ -383,8 +380,7 @@
   struct cached_resolve *resolve;
   connection_t *pendconn;
 
-  strncpy(search.address, address, MAX_ADDRESSLEN);
-  search.address[MAX_ADDRESSLEN-1] = 0;
+  strlcpy(search.address, address, sizeof(search.address));
 
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
   if(!resolve) {
@@ -454,8 +450,7 @@
   connection_t *pendconn;
   circuit_t *circ;
 
-  strncpy(search.address, address, MAX_ADDRESSLEN);
-  search.address[MAX_ADDRESSLEN-1] = 0;
+  strlcpy(search.address, address, sizeof(search.address));
 
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
   if(!resolve) {



More information about the tor-commits mailing list