Allow socks4_server_reply version to be 0 (for tor-resolve)

This commit is contained in:
rl1987 2018-09-12 11:18:43 +03:00 committed by Nick Mathewson
parent 83af6d6149
commit d49baa77b5
2 changed files with 7 additions and 8 deletions

View File

@ -1694,7 +1694,6 @@ socks4_server_reply_new(void)
socks4_server_reply_t *val = trunnel_calloc(1, sizeof(socks4_server_reply_t)); socks4_server_reply_t *val = trunnel_calloc(1, sizeof(socks4_server_reply_t));
if (NULL == val) if (NULL == val)
return NULL; return NULL;
val->version = 4;
return val; return val;
} }
@ -1724,7 +1723,7 @@ socks4_server_reply_get_version(const socks4_server_reply_t *inp)
int int
socks4_server_reply_set_version(socks4_server_reply_t *inp, uint8_t val) socks4_server_reply_set_version(socks4_server_reply_t *inp, uint8_t val)
{ {
if (! ((val == 4))) { if (! ((val == 0 || val == 4))) {
TRUNNEL_SET_ERROR_CODE(inp); TRUNNEL_SET_ERROR_CODE(inp);
return -1; return -1;
} }
@ -1771,7 +1770,7 @@ socks4_server_reply_check(const socks4_server_reply_t *obj)
return "Object was NULL"; return "Object was NULL";
if (obj->trunnel_error_code_) if (obj->trunnel_error_code_)
return "A set function failed on this object"; return "A set function failed on this object";
if (! (obj->version == 4)) if (! (obj->version == 0 || obj->version == 4))
return "Integer out of bounds"; return "Integer out of bounds";
return NULL; return NULL;
} }
@ -1785,7 +1784,7 @@ socks4_server_reply_encoded_len(const socks4_server_reply_t *obj)
return -1; return -1;
/* Length of u8 version IN [4] */ /* Length of u8 version IN [0, 4] */
result += 1; result += 1;
/* Length of u8 status */ /* Length of u8 status */
@ -1823,7 +1822,7 @@ socks4_server_reply_encode(uint8_t *output, const size_t avail, const socks4_ser
trunnel_assert(encoded_len >= 0); trunnel_assert(encoded_len >= 0);
#endif #endif
/* Encode u8 version IN [4] */ /* Encode u8 version IN [0, 4] */
trunnel_assert(written <= avail); trunnel_assert(written <= avail);
if (avail - written < 1) if (avail - written < 1)
goto truncated; goto truncated;
@ -1886,11 +1885,11 @@ socks4_server_reply_parse_into(socks4_server_reply_t *obj, const uint8_t *input,
ssize_t result = 0; ssize_t result = 0;
(void)result; (void)result;
/* Parse u8 version IN [4] */ /* Parse u8 version IN [0, 4] */
CHECK_REMAINING(1, truncated); CHECK_REMAINING(1, truncated);
obj->version = (trunnel_get_uint8(ptr)); obj->version = (trunnel_get_uint8(ptr));
remaining -= 1; ptr += 1; remaining -= 1; ptr += 1;
if (! (obj->version == 4)) if (! (obj->version == 0 || obj->version == 4))
goto fail; goto fail;
/* Parse u8 status */ /* Parse u8 status */

View File

@ -86,7 +86,7 @@ struct socks4_client_request {
} }
struct socks4_server_reply { struct socks4_server_reply {
u8 version IN [4]; u8 version IN [0,4];
u8 status; u8 status;
u16 port; u16 port;
u32 addr; u32 addr;