Replace sprintf with snprintf

svn:r2602
This commit is contained in:
Nick Mathewson
2004-10-27 05:53:07 +00:00
parent 7d4854301c
commit bc62f8e983
13 changed files with 39 additions and 36 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ static INLINE char *format_msg(char *buf, size_t buf_len,
/** Helper: sends a message to the appropriate logfiles, at loglevel
* <b>severity</b>. If provided, <b>funcname</b> is prepended to the
* message. The actual message is derived as from vsprintf(format,ap).
* message. The actual message is derived as from vsnprintf(format,ap).
*/
static void
logv(int severity, const char *funcname, const char *format, va_list ap)
+2 -2
View File
@@ -294,12 +294,12 @@ tor_tls_context_new(crypto_pk_env_t *identity,
EVP_PKEY *pkey = NULL;
tor_tls_context *result = NULL;
X509 *cert = NULL, *idcert = NULL;
char nn2[1024];
char nn2[128];
int client_only;
SSL_CTX **ctx;
if (!nickname)
nickname = "null";
sprintf(nn2, "%s <identity>", nickname);
snprintf(nn2, sizeof(nn2), "%s <identity>", nickname);
tor_tls_init();
+4 -2
View File
@@ -1763,6 +1763,7 @@ char *expand_filename(const char *filename)
tor_assert(filename);
/* XXXX Should eventually check for ~username/ */
if (!strncmp(filename,"~/",2)) {
size_t len;
const char *home = getenv("HOME");
char *result;
if (!home) {
@@ -1770,8 +1771,9 @@ char *expand_filename(const char *filename)
return NULL;
}
/* minus two characters for ~/, plus one for /, plus one for NUL. */
result = tor_malloc(strlen(home)+strlen(filename)+16);
sprintf(result,"%s/%s",home,filename+2);
len = strlen(home)+strlen(filename)+16;
result = tor_malloc(len);
snprintf(result,len,"%s/%s",home,filename+2);
return result;
} else {
return tor_strdup(filename);