diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-01-03 17:53:20 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-01-03 17:53:20 +0000 |
commit | fca7ba977765061731873ef36a32777f0df8ee89 (patch) | |
tree | 1daf736f4f1514112bb85c8aa5be6dfa7745d5a8 /src/or/router.c | |
parent | 59504f483157420dc2562e8a750070965a2cdc42 (diff) | |
download | tor-fca7ba977765061731873ef36a32777f0df8ee89.tar.gz tor-fca7ba977765061731873ef36a32777f0df8ee89.zip |
Resolve task 42: find where 19-char nicknames were getting truncated when read from certs, and fix it. Also audit use of MAX_NICKNAME_LEN; no other badness found, but some docs/code cleaned up a touch.
svn:r3244
Diffstat (limited to 'src/or/router.c')
-rw-r--r-- | src/or/router.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/or/router.c b/src/or/router.c index 30fe73448d..d91546d6ff 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -240,7 +240,8 @@ int init_keys(void) { */ char keydir[512]; char keydir2[512]; - char fingerprint[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3]; + char fingerprint[FINGERPRINT_LEN+1]; + char fingerprint_line[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3];/*nickname fp\n\0 */ char *cp; const char *tmp, *mydesc, *datadir; crypto_pk_env_t *prkey; @@ -333,16 +334,17 @@ int init_keys(void) { /* 5. Dump fingerprint to 'fingerprint' */ tor_snprintf(keydir,sizeof(keydir),"%s/fingerprint", datadir); log_fn(LOG_INFO,"Dumping fingerprint to %s...",keydir); - tor_assert(strlen(options->Nickname) <= MAX_NICKNAME_LEN); - strlcpy(fingerprint, options->Nickname, sizeof(fingerprint)); - strlcat(fingerprint, " ", sizeof(fingerprint)); - if (crypto_pk_get_fingerprint(get_identity_key(), - fingerprint+strlen(fingerprint), 1)<0) { + if (crypto_pk_get_fingerprint(get_identity_key(), fingerprint, 1)<0) { log_fn(LOG_ERR, "Error computing fingerprint"); return -1; } - strlcat(fingerprint, "\n", sizeof(fingerprint)); - if (write_str_to_file(keydir, fingerprint, 0)) + tor_assert(strlen(options->Nickname) <= MAX_NICKNAME_LEN); + if (tor_snprintf(fingerprint_line, sizeof(fingerprint_line), + "%s %s\n",options->Nickname, fingerprint) < 0) { + log_fn(LOG_ERR, "Error writing fingerprint line"); + return -1; + } + if (write_str_to_file(keydir, fingerprint_line, 0)) return -1; if (!authdir_mode(options)) return 0; |