Use strlcpy, not strncpy

svn:r2603
This commit is contained in:
Nick Mathewson
2004-10-27 06:03:28 +00:00
parent bc62f8e983
commit f67f83b1fa
4 changed files with 10 additions and 18 deletions
+1 -2
View File
@@ -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);
+3 -3
View File
@@ -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);