summaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2011-04-26 05:07:37 +0200
committerSebastian Hahn <sebastian@torproject.org>2011-04-26 05:08:32 +0200
commit4c789ec08c8d52c3aab3ab775a86fe2350d584b5 (patch)
treec04a01d4db277385f74f1740e3254730796ad7d5 /src/or/config.c
parentf3b58dfa53d87656f558a97bc28a333bdea06017 (diff)
downloadtor-4c789ec08c8d52c3aab3ab775a86fe2350d584b5.tar.gz
tor-4c789ec08c8d52c3aab3ab775a86fe2350d584b5.zip
Don't leak the local hostname in relay nicknames
Fixes bug 2979, reported by tagnaq.
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c55
1 files changed, 0 insertions, 55 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 3770301370..9675c73c99 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2500,54 +2500,6 @@ is_local_addr(const tor_addr_t *addr)
return 0;
}
-/** Called when we don't have a nickname set. Try to guess a good nickname
- * based on the hostname, and return it in a newly allocated string. If we
- * can't, return NULL and let the caller warn if it wants to. */
-static char *
-get_default_nickname(void)
-{
- static const char * const bad_default_nicknames[] = {
- "localhost",
- NULL,
- };
- char localhostname[256];
- char *cp, *out, *outp;
- int i;
-
- if (gethostname(localhostname, sizeof(localhostname)) < 0)
- return NULL;
-
- /* Put it in lowercase; stop at the first dot. */
- if ((cp = strchr(localhostname, '.')))
- *cp = '\0';
- tor_strlower(localhostname);
-
- /* Strip invalid characters. */
- cp = localhostname;
- out = outp = tor_malloc(strlen(localhostname) + 1);
- while (*cp) {
- if (strchr(LEGAL_NICKNAME_CHARACTERS, *cp))
- *outp++ = *cp++;
- else
- cp++;
- }
- *outp = '\0';
-
- /* Enforce length. */
- if (strlen(out) > MAX_NICKNAME_LEN)
- out[MAX_NICKNAME_LEN]='\0';
-
- /* Check for dumb names. */
- for (i = 0; bad_default_nicknames[i]; ++i) {
- if (!strcmp(out, bad_default_nicknames[i])) {
- tor_free(out);
- return NULL;
- }
- }
-
- return out;
-}
-
/** Release storage held by <b>options</b>. */
static void
config_free(config_format_t *fmt, void *options)
@@ -2976,14 +2928,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->Nickname == NULL) {
if (server_mode(options)) {
- if (!(options->Nickname = get_default_nickname())) {
- log_notice(LD_CONFIG, "Couldn't pick a nickname based on "
- "our hostname; using %s instead.", UNNAMED_ROUTER_NICKNAME);
options->Nickname = tor_strdup(UNNAMED_ROUTER_NICKNAME);
- } else {
- log_notice(LD_CONFIG, "Choosing default nickname '%s'",
- options->Nickname);
- }
}
} else {
if (!is_legal_nickname(options->Nickname)) {