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
This commit is contained in:
Nick Mathewson 2005-01-03 17:53:20 +00:00
parent 59504f4831
commit fca7ba9777
6 changed files with 22 additions and 14 deletions

View File

@ -586,8 +586,10 @@ tor_tls_peer_has_cert(tor_tls *tls)
return 1;
}
/** Return the nickname (if any) that the peer connected on <b>tls</b>
* claims to have.
/** Write the nickname (if any) that the peer connected on <b>tls</b>
* claims to have into the first <b>buflen</b> characters of <b>buf</b>.
* Truncate the nickname if it is longer than buflen-1 characters. Always
* NUL-terminate. Return 0 on success, -1 on failure.
*/
int
tor_tls_get_peer_cert_nickname(tor_tls *tls, char *buf, size_t buflen)

View File

@ -927,7 +927,7 @@ resolve_my_address(const char *address, uint32_t *addr)
}
/** Called when we don't have a nickname set. Try to guess a good
* nickname based on the hostname, and return it. */
* nickname based on the hostname, and return it in a newly allocated string. */
static char *
get_default_nickname(void)
{

View File

@ -354,7 +354,7 @@ connection_tls_finish_handshake(connection_t *conn) {
}
}
/* Okay; the other side is an OR or a post-0.0.8 OP (with a cert). */
if (tor_tls_get_peer_cert_nickname(conn->tls, nickname, MAX_NICKNAME_LEN)) {
if (tor_tls_get_peer_cert_nickname(conn->tls, nickname, sizeof(nickname))) {
log_fn(LOG_WARN,"Other side (%s:%d) has a cert without a valid nickname. Closing.",
conn->address, conn->port);
return -1;

View File

@ -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;

View File

@ -311,8 +311,8 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, int warn_if_do
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
SMARTLIST_FOREACH(nickname_list, const char *, nick, {
if (strlen(nick) > MAX_HEX_NICKNAME_LEN) {
log_fn(LOG_WARN,"Nickname too long; skipping");
if (!is_legal_nickname_or_hexdigest(nick)) {
log_fn(LOG_WARN,"Nickname %s is misformed; skipping", nick);
continue;
}
router = router_get_by_nickname(nick);

View File

@ -340,6 +340,10 @@ router_parse_routerlist_from_directory(const char *str,
goto err;
/* now we know tok->n_args == 1, so it's safe to access tok->args[0] */
if (!is_legal_nickname(tok->args[0])) {
log_fn(LOG_WARN, "Directory nickname '%s' is misformed", tok->args[0]);
goto err;
}
strlcpy(dirnickname, tok->args[0], sizeof(dirnickname));
SMARTLIST_FOREACH(tokens, directory_token_t *, tok, token_free(tok));