mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
socks: add assertion for hostname length in SOCKS5 connect
socks5_req0_init() rejects hostnames longer than 255 bytes, but the later cast to unsigned char in socks5_req1_init() has no local indication that it is safe. Add a DEBUGASSERT and comment to document the invariant and guard against future refactoring. Closes #21157
This commit is contained in:
parent
fb6925c243
commit
2c26cea5ec
@ -808,6 +808,10 @@ static CURLproxycode socks5_req1_init(struct socks_state *sx,
|
||||
}
|
||||
else {
|
||||
const size_t hostname_len = strlen(sx->hostname);
|
||||
/* socks5_req0_init() already rejects hostnames longer than 255 bytes, so
|
||||
this cast to unsigned char is safe. Assert to guard against future
|
||||
refactoring that might remove or reorder that earlier check. */
|
||||
DEBUGASSERT(hostname_len <= 255);
|
||||
desttype = 3;
|
||||
destination = (const unsigned char *)sx->hostname;
|
||||
destlen = (unsigned char)hostname_len; /* one byte length */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user