mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Use strlcpy, not strncpy
svn:r2603
This commit is contained in:
+1
-2
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user