diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-10-27 06:03:28 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-10-27 06:03:28 +0000 |
commit | f67f83b1facdb6515fb0996fd70d172df37d5962 (patch) | |
tree | dd45daf4d906587786b82ae43b5e4584bc0e21cb /src/or | |
parent | bc62f8e983e913c8a37f3412466b8bc9d360b614 (diff) | |
download | tor-f67f83b1facdb6515fb0996fd70d172df37d5962.tar.gz tor-f67f83b1facdb6515fb0996fd70d172df37d5962.zip |
Use strlcpy, not strncpy
svn:r2603
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/dirserv.c | 4 | ||||
-rw-r--r-- | src/or/dns.c | 15 |
2 files changed, 6 insertions, 13 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index d78ab7c45c..f108178464 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -386,9 +386,7 @@ dirserv_add_descriptor(const char **desc) 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. */ diff --git a/src/or/dns.c b/src/or/dns.c index 17bb58c594..b097c1d24a 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -201,8 +201,7 @@ int dns_resolve(connection_t *exitconn) { 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 @@ int dns_resolve(connection_t *exitconn) { 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 @@ void connection_dns_remove(connection_t *conn) 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 @@ void dns_cancel_pending_resolve(char *address) { 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 @@ static void dns_found_answer(char *address, uint32_t addr, char outcome) { 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) { |