Commit 2f954af9 authored by Guinness's avatar Guinness
Browse files

Returns 0xF6 only if BAD_HOSTNAME

This commit modifies the behavior of `parse_extended_address` in such a
way that if it fails, it will always return a `BAD_HOSTNAME` value,
which is then used to return the 0xF6 extended error code.
This way, in any case that is not a valid v2 address, we return the 0xF6
error code, which is the expected behavior.
parent c314bbae
Pipeline #429 failed with stage
......@@ -1585,8 +1585,7 @@ consider_plaintext_ports(entry_connection_t *conn, uint16_t port)
* ONION_V2_HOSTNAME or ONION_V3_HOSTNAME depending on the HS version.
*
* If address is of the form "y.onion" with a badly-formed handle y:
* Return BAD_HOSTNAME or BAD_V3_HOSTNAME depending on the HS version
* and log a message.
* Return BAD_HOSTNAME and log a message.
*
* If address is of the form "y.exit":
* Put a NUL after y and return EXIT_HOSTNAME.
......@@ -1627,7 +1626,7 @@ parse_extended_hostname(char *address, hostname_type_t *type_out)
q = (NULL == q) ? address : q + 1;
if (strlcpy(query, q, HS_SERVICE_ADDR_LEN_BASE32+1) >=
HS_SERVICE_ADDR_LEN_BASE32+1) {
*type_out = BAD_V3_HOSTNAME;
*type_out = BAD_HOSTNAME;
goto failed;
}
if (q != address) {
......@@ -1648,7 +1647,6 @@ parse_extended_hostname(char *address, hostname_type_t *type_out)
if (hs_address_is_valid(query)) {
goto success;
}
*type_out = BAD_V3_HOSTNAME;
goto failed;
}
......@@ -1666,6 +1664,9 @@ parse_extended_hostname(char *address, hostname_type_t *type_out)
log_warn(LD_APP, "Invalid %shostname %s; rejecting",
is_onion ? "onion " : "",
safe_str_client(address));
if (*type_out == ONION_V3_HOSTNAME) {
*type_out = BAD_HOSTNAME;
}
return false;
}
......@@ -2142,7 +2143,7 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
if (!parse_extended_hostname(socks->address, &addresstype)) {
control_event_client_status(LOG_WARN, "SOCKS_BAD_HOSTNAME HOSTNAME=%s",
escaped(socks->address));
if (addresstype == BAD_V3_HOSTNAME) {
if (addresstype == BAD_HOSTNAME) {
conn->socks_request->socks_extended_error_code = SOCKS5_HS_BAD_ADDRESS;
}
connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
......
......@@ -74,7 +74,6 @@ entry_connection_t *EDGE_TO_ENTRY_CONN(edge_connection_t *);
/** Possible return values for parse_extended_hostname. */
typedef enum hostname_type_t {
BAD_HOSTNAME,
BAD_V3_HOSTNAME,
EXIT_HOSTNAME,
NORMAL_HOSTNAME,
ONION_V2_HOSTNAME,
......
......@@ -826,11 +826,11 @@ test_parse_extended_hostname(void *arg)
/* Invalid v3 address. */
tt_assert(!parse_extended_hostname(address9, &type));
tt_int_op(type, OP_EQ, BAD_V3_HOSTNAME);
tt_int_op(type, OP_EQ, BAD_HOSTNAME);
/* Invalid v3 address: too long */
tt_assert(!parse_extended_hostname(address10, &type));
tt_int_op(type, OP_EQ, BAD_V3_HOSTNAME);
tt_int_op(type, OP_EQ, BAD_HOSTNAME);
done: ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment