diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-01-09 19:14:51 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-01-09 19:14:51 -0500 |
commit | b1ee1a719db0a47fa27a8efd9a6e7e443dca2550 (patch) | |
tree | 7ab4649584c6eb213cc37999d8a6b64e65f44646 /src/common | |
parent | 3fadc074caa2f69b9d4ef17339a42dc9fbe4ad9e (diff) | |
download | tor-b1ee1a719db0a47fa27a8efd9a6e7e443dca2550.tar.gz tor-b1ee1a719db0a47fa27a8efd9a6e7e443dca2550.zip |
Tweaks for bug4413 fix
The thing that's limited to 63 bytes is a "label", not a hostname.
Docment input constraints and behavior on bogus inputs.
Generally it's better to check for overflow-like conditions before
than after. In this case, it's not a true overflow, so we're okay,
but let's be consistent.
pedantic less->fewer in the documentation
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 9ee3d989a3..7edc7f228e 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -82,8 +82,8 @@ #include "sha256.c" #define SHA256_Final(a,b) sha256_done(b,a) -/* Bug 4413*/ -#define MAX_HOSTNAME_SIZE 63 +/** Longest recognized */ +#define MAX_DNS_LABEL_SIZE 63 static unsigned char * SHA256(const unsigned char *m, size_t len, unsigned char *d) @@ -2545,9 +2545,12 @@ crypto_rand_double(void) } /** Generate and return a new random hostname starting with <b>prefix</b>, - * ending with <b>suffix</b>, and containing no less than + * ending with <b>suffix</b>, and containing no fewer than * <b>min_rand_len</b> and no more than <b>max_rand_len</b> random base32 - * characters between. */ + * characters between. + * + * Clip <b>max_rand_len</b> to MAX_DNS_LABEL_SIZE. + **/ char * crypto_random_hostname(int min_rand_len, int max_rand_len, const char *prefix, const char *suffix) @@ -2556,12 +2559,12 @@ crypto_random_hostname(int min_rand_len, int max_rand_len, const char *prefix, int randlen, rand_bytes_len; size_t resultlen, prefixlen; - tor_assert(max_rand_len >= min_rand_len); + if (max_rand_len > MAX_DNS_LABEL_SIZE) + max_rand_len = MAX_DNS_LABEL_SIZE; + if (min_rand_len > max_rand_len) + min_rand_len = max_rand_len; randlen = min_rand_len + crypto_rand_int(max_rand_len - min_rand_len + 1); - if (randlen > MAX_HOSTNAME_SIZE) { - randlen = MAX_HOSTNAME_SIZE; - } prefixlen = strlen(prefix); resultlen = prefixlen + strlen(suffix) + randlen + 16; |