diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-05-23 14:38:13 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-07-12 11:41:44 -0400 |
commit | 4c845fcf9e5b009a5e8d29f4c54eb7a98513e436 (patch) | |
tree | 02410db2ec7c813ca0bc7bbf49a88390ea907513 | |
parent | a6af21c1b7f1751b96352a5080e0b3fb7e6201a9 (diff) | |
download | tor-4c845fcf9e5b009a5e8d29f4c54eb7a98513e436.tar.gz tor-4c845fcf9e5b009a5e8d29f4c54eb7a98513e436.zip |
Rework socks_request_set_socks5_error() with trunnel
-rw-r--r-- | src/or/proto_socks.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/or/proto_socks.c b/src/or/proto_socks.c index dab349bbea..9dbd688b75 100644 --- a/src/or/proto_socks.c +++ b/src/or/proto_socks.c @@ -858,12 +858,31 @@ static void socks_request_set_socks5_error(socks_request_t *req, socks5_reply_status_t reason) { - req->replylen = 10; - memset(req->reply,0,10); + socks5_server_reply_t *trunnel_resp = socks5_server_reply_new(); - req->reply[0] = 0x05; // VER field. - req->reply[1] = reason; // REP field. - req->reply[3] = 0x01; // ATYP field. + socks5_server_reply_set_version(trunnel_resp, 0x05); + socks5_server_reply_set_reply(trunnel_resp, reason); + socks5_server_reply_set_atype(trunnel_resp, 0x01); + + const char *errmsg = socks5_server_reply_check(trunnel_resp); + if (errmsg) { + log_warn(LD_APP, "socks5: reply validation failed: %s", + errmsg); + goto end; + } + + ssize_t encoded = socks5_server_reply_encode(req->reply, + sizeof(req->reply), + trunnel_resp); + if (encoded < 0) { + log_warn(LD_APP, "socks5: reply encoding failed: %d", + (int)encoded); + } else { + req->replylen = (size_t)encoded; + } + + end: + socks5_server_reply_free(trunnel_resp); } static const char SOCKS_PROXY_IS_NOT_AN_HTTP_PROXY_MSG[] = |