mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +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);
|
len = BIO_get_mem_data(bio, &cp);
|
||||||
tor_assert(len >= 0);
|
tor_assert(len >= 0);
|
||||||
s = tor_malloc(len+1);
|
s = tor_malloc(len+1);
|
||||||
strncpy(s, cp, len);
|
strlcpy(s, cp, len+1);
|
||||||
s[len] = '\0';
|
|
||||||
r = write_str_to_file(fname, s, 0);
|
r = write_str_to_file(fname, s, 0);
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
free(s);
|
free(s);
|
||||||
|
@ -195,8 +195,7 @@ char *tor_strndup(const char *s, size_t n) {
|
|||||||
char *dup;
|
char *dup;
|
||||||
tor_assert(s);
|
tor_assert(s);
|
||||||
dup = tor_malloc(n+1);
|
dup = tor_malloc(n+1);
|
||||||
strncpy(dup, s, n);
|
strlcpy(dup, s, n+1);
|
||||||
dup[n] = 0;
|
|
||||||
return dup;
|
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);
|
log_fn(LOG_WARN, "Couldn't find $HOME environment variable while expanding %s", filename);
|
||||||
return NULL;
|
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;
|
len = strlen(home)+strlen(filename)+16;
|
||||||
result = tor_malloc(len);
|
result = tor_malloc(len);
|
||||||
snprintf(result,len,"%s/%s",home,filename+2);
|
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->nickname = tor_strdup(ri->nickname);
|
||||||
ent->published = ri->published_on;
|
ent->published = ri->published_on;
|
||||||
ent->desc_len = desc_len;
|
ent->desc_len = desc_len;
|
||||||
ent->descriptor = tor_malloc(desc_len+1);
|
ent->descriptor = tor_strndup(start,desc_len);
|
||||||
strncpy(ent->descriptor, start, desc_len);
|
|
||||||
ent->descriptor[desc_len] = '\0';
|
|
||||||
ent->router = ri;
|
ent->router = ri;
|
||||||
/* XXX008 is ent->verified useful/used for anything? */
|
/* XXX008 is ent->verified useful/used for anything? */
|
||||||
ent->verified = verified; /* XXXX008 support other possibilities. */
|
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);
|
purge_expired_resolves(now);
|
||||||
|
|
||||||
/* now check the tree to see if 'address' is already there. */
|
/* now check the tree to see if 'address' is already there. */
|
||||||
strncpy(search.address, exitconn->address, MAX_ADDRESSLEN);
|
strlcpy(search.address, exitconn->address, sizeof(search.address));
|
||||||
search.address[MAX_ADDRESSLEN-1] = 0;
|
|
||||||
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
||||||
if(resolve) { /* already there */
|
if(resolve) { /* already there */
|
||||||
switch(resolve->state) {
|
switch(resolve->state) {
|
||||||
@ -237,8 +236,7 @@ int dns_resolve(connection_t *exitconn) {
|
|||||||
resolve = tor_malloc_zero(sizeof(struct cached_resolve));
|
resolve = tor_malloc_zero(sizeof(struct cached_resolve));
|
||||||
resolve->state = CACHE_STATE_PENDING;
|
resolve->state = CACHE_STATE_PENDING;
|
||||||
resolve->expire = now + MAX_DNS_ENTRY_AGE;
|
resolve->expire = now + MAX_DNS_ENTRY_AGE;
|
||||||
strncpy(resolve->address, exitconn->address, MAX_ADDRESSLEN);
|
strlcpy(resolve->address, exitconn->address, sizeof(resolve->address));
|
||||||
resolve->address[MAX_ADDRESSLEN-1] = 0;
|
|
||||||
|
|
||||||
/* add us to the pending list */
|
/* add us to the pending list */
|
||||||
pending_connection = tor_malloc_zero(sizeof(struct pending_connection_t));
|
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->type == CONN_TYPE_EXIT);
|
||||||
tor_assert(conn->state == EXIT_CONN_STATE_RESOLVING);
|
tor_assert(conn->state == EXIT_CONN_STATE_RESOLVING);
|
||||||
|
|
||||||
strncpy(search.address, conn->address, MAX_ADDRESSLEN);
|
strlcpy(search.address, conn->address, sizeof(search.address));
|
||||||
search.address[MAX_ADDRESSLEN-1] = 0;
|
|
||||||
|
|
||||||
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
||||||
if(!resolve) {
|
if(!resolve) {
|
||||||
@ -383,8 +380,7 @@ void dns_cancel_pending_resolve(char *address) {
|
|||||||
struct cached_resolve *resolve;
|
struct cached_resolve *resolve;
|
||||||
connection_t *pendconn;
|
connection_t *pendconn;
|
||||||
|
|
||||||
strncpy(search.address, address, MAX_ADDRESSLEN);
|
strlcpy(search.address, address, sizeof(search.address));
|
||||||
search.address[MAX_ADDRESSLEN-1] = 0;
|
|
||||||
|
|
||||||
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
||||||
if(!resolve) {
|
if(!resolve) {
|
||||||
@ -454,8 +450,7 @@ static void dns_found_answer(char *address, uint32_t addr, char outcome) {
|
|||||||
connection_t *pendconn;
|
connection_t *pendconn;
|
||||||
circuit_t *circ;
|
circuit_t *circ;
|
||||||
|
|
||||||
strncpy(search.address, address, MAX_ADDRESSLEN);
|
strlcpy(search.address, address, sizeof(search.address));
|
||||||
search.address[MAX_ADDRESSLEN-1] = 0;
|
|
||||||
|
|
||||||
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
|
||||||
if(!resolve) {
|
if(!resolve) {
|
||||||
|
Loading…
Reference in New Issue
Block a user