diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 9 | ||||
-rw-r--r-- | src/or/control.c | 10 | ||||
-rw-r--r-- | src/or/router.c | 16 | ||||
-rw-r--r-- | src/test/test_pt.c | 2 | ||||
-rw-r--r-- | src/test/test_util.c | 15 |
5 files changed, 43 insertions, 9 deletions
diff --git a/src/common/util.c b/src/common/util.c index 276c6dd13..30bf6879a 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -870,6 +870,9 @@ tor_digest256_is_zero(const char *digest) /* Helper: common code to check whether the result of a strtol or strtoul or * strtoll is correct. */ #define CHECK_STRTOX_RESULT() \ + /* Did an overflow occur? */ \ + if (errno == ERANGE) \ + goto err; \ /* Was at least one character converted? */ \ if (endptr == s) \ goto err; \ @@ -911,6 +914,8 @@ tor_parse_long(const char *s, int base, long min, long max, *ok = 0; return 0; } + + errno = 0; r = strtol(s, &endptr, base); CHECK_STRTOX_RESULT(); } @@ -928,6 +933,8 @@ tor_parse_ulong(const char *s, int base, unsigned long min, *ok = 0; return 0; } + + errno = 0; r = strtoul(s, &endptr, base); CHECK_STRTOX_RESULT(); } @@ -939,6 +946,7 @@ tor_parse_double(const char *s, double min, double max, int *ok, char **next) char *endptr; double r; + errno = 0; r = strtod(s, &endptr); CHECK_STRTOX_RESULT(); } @@ -958,6 +966,7 @@ tor_parse_uint64(const char *s, int base, uint64_t min, return 0; } + errno = 0; #ifdef HAVE_STRTOULL r = (uint64_t)strtoull(s, &endptr, base); #elif defined(_WIN32) diff --git a/src/or/control.c b/src/or/control.c index 397bb53ab..ec0bb8a7c 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -2986,13 +2986,13 @@ handle_control_authchallenge(control_connection_t *conn, uint32_t len, cp += strlen("SAFECOOKIE"); } else { connection_write_str_to_buf("513 AUTHCHALLENGE only supports SAFECOOKIE " - "authentication", conn); + "authentication\r\n", conn); connection_mark_for_close(TO_CONN(conn)); return -1; } if (!authentication_cookie_is_set) { - connection_write_str_to_buf("515 Cookie authentication is disabled", conn); + connection_write_str_to_buf("515 Cookie authentication is disabled\r\n", conn); connection_mark_for_close(TO_CONN(conn)); return -1; } @@ -3003,7 +3003,7 @@ handle_control_authchallenge(control_connection_t *conn, uint32_t len, decode_escaped_string(cp, len - (cp - body), &client_nonce, &client_nonce_len); if (newcp == NULL) { - connection_write_str_to_buf("513 Invalid quoted client nonce", + connection_write_str_to_buf("513 Invalid quoted client nonce\r\n", conn); connection_mark_for_close(TO_CONN(conn)); return -1; @@ -3017,7 +3017,7 @@ handle_control_authchallenge(control_connection_t *conn, uint32_t len, if (base16_decode(client_nonce, client_nonce_len, cp, client_nonce_encoded_len) < 0) { - connection_write_str_to_buf("513 Invalid base16 client nonce", + connection_write_str_to_buf("513 Invalid base16 client nonce\r\n", conn); connection_mark_for_close(TO_CONN(conn)); tor_free(client_nonce); @@ -3030,7 +3030,7 @@ handle_control_authchallenge(control_connection_t *conn, uint32_t len, cp += strspn(cp, " \t\n\r"); if (*cp != '\0' || cp != body + len) { - connection_write_str_to_buf("513 Junk at end of AUTHCHALLENGE command", + connection_write_str_to_buf("513 Junk at end of AUTHCHALLENGE command\r\n", conn); connection_mark_for_close(TO_CONN(conn)); tor_free(client_nonce); diff --git a/src/or/router.c b/src/or/router.c index 4cdfd02e5..c51bb5dc4 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -1530,10 +1530,18 @@ router_rebuild_descriptor(int force) if (p->type == CONN_TYPE_OR_LISTENER && ! p->no_advertise && ! p->ipv4_only && - tor_addr_family(&p->addr) == AF_INET6 && - ! tor_addr_is_internal(&p->addr, 1)) { - ipv6_orport = p; - break; + tor_addr_family(&p->addr) == AF_INET6) { + if (! tor_addr_is_internal(&p->addr, 0)) { + ipv6_orport = p; + break; + } else { + char addrbuf[TOR_ADDR_BUF_LEN]; + log_warn(LD_CONFIG, + "Unable to use configured IPv6 address \"%s\" in a " + "descriptor. Skipping it. " + "Try specifying a globally reachable address explicitly. ", + tor_addr_to_str(addrbuf, &p->addr, sizeof(addrbuf), 1)); + } } } SMARTLIST_FOREACH_END(p); if (ipv6_orport) { diff --git a/src/test/test_pt.c b/src/test/test_pt.c index 9d6aa09f0..201f78ea5 100644 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@ -94,6 +94,8 @@ test_pt_protocol(void) managed_proxy_t *mp = tor_malloc_zero(sizeof(managed_proxy_t)); mp->conf_state = PT_PROTO_LAUNCHED; mp->transports = smartlist_new(); + mp->argv = tor_malloc_zero(sizeof(char*)*2); + mp->argv[0] = tor_strdup("<testcase>"); /* various wrong protocol runs: */ diff --git a/src/test/test_util.c b/src/test/test_util.c index 7a455e06a..e8f043a2c 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -755,6 +755,21 @@ test_util_strmisc(void) test_eq(-10.0, d); } + { + /* Test tor_parse_* where we overflow/underflow the underlying type. */ + /* This string should overflow 64-bit ints. */ +#define TOOBIG "100000000000000000000000000" + test_eq(0L, tor_parse_long(TOOBIG, 10, LONG_MIN, LONG_MAX, &i, NULL)); + test_eq(i, 0); + test_eq(0L, tor_parse_long("-"TOOBIG, 10, LONG_MIN, LONG_MAX, &i, NULL)); + test_eq(i, 0); + test_eq(0UL, tor_parse_ulong(TOOBIG, 10, 0, ULONG_MAX, &i, NULL)); + test_eq(i, 0); + test_eq(U64_LITERAL(0), tor_parse_uint64(TOOBIG, 10, + 0, UINT64_MAX, &i, NULL)); + test_eq(i, 0); + } + /* Test snprintf */ /* Returning -1 when there's not enough room in the output buffer */ test_eq(-1, tor_snprintf(buf, 0, "Foo")); |