diff --git a/src/or/buffers.c b/src/or/buffers.c
index 4cdc03bc03ec9e2cb01eff54bd5890af4905e30a..f0d7e60794295c8affc8085137cfef36c6f2ecd2 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -2063,9 +2063,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
               socks_request_set_socks5_error(req, SOCKS5_NOT_ALLOWED);
               return -1;
             }
-          }
-
-          if (!string_is_valid_hostname(req->address)) {
+          } else if (!string_is_valid_hostname(req->address)) {
             socks_request_set_socks5_error(req, SOCKS5_GENERAL_ERROR);
 
             log_warn(LD_PROTOCOL,