mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Use strlcpy, not strncpy
svn:r2603
This commit is contained in:
parent
bc62f8e983
commit
f67f83b1fa
@ -462,8 +462,7 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
|
||||
len = BIO_get_mem_data(bio, &cp);
|
||||
tor_assert(len >= 0);
|
||||
s = tor_malloc(len+1);
|
||||
strncpy(s, cp, len);
|
||||
s[len] = '\0';
|
||||
strlcpy(s, cp, len+1);
|
||||
r = write_str_to_file(fname, s, 0);
|
||||
BIO_free(bio);
|
||||
free(s);
|
||||
|
@ -195,8 +195,7 @@ char *tor_strndup(const char *s, size_t n) {
|
||||
char *dup;
|
||||
tor_assert(s);
|
||||
dup = tor_malloc(n+1);
|
||||
strncpy(dup, s, n);
|
||||
dup[n] = 0;
|
||||
strlcpy(dup, s, n+1);
|
||||
return dup;
|
||||
}
|
||||
|
||||
@ -1770,7 +1769,8 @@ char *expand_filename(const char *filename)
|
||||
log_fn(LOG_WARN, "Couldn't find $HOME environment variable while expanding %s", filename);
|
||||
return NULL;
|
||||
}
|
||||
/* minus two characters for ~/, plus one for /, plus one for NUL. */
|
||||
/* minus two characters for ~/, plus one for /, plus one for NUL.
|
||||
* Round up to 16 in case we can't do math. */
|
||||
len = strlen(home)+strlen(filename)+16;
|
||||
result = tor_malloc(len);
|
||||
snprintf(result,len,"%s/%s",home,filename+2);
|
||||
|
@ -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. */
|
||||
|
15
src/or/dns.c
15
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user