socks: a host name with control bytes or spaces is refused where it is read

This commit is contained in:
Vladimir Dubrovin committed 2026-11-18 20:50:51 +03:00
1 parent f105a27e68
commit 4f4862e2c1
4 files changed
+19

No files matched your search

+15
View File
@@ -569,11 +569,26 @@ int parsehost(int family, unsigned char *host, struct sockaddr *sa){
return ret;
}
/* A host name is written into the request lines of parent protocols and
matched against rules, so a control byte or a space in it could end a
line early or pose as another destination. A name carrying one is
refused where it is read, and every name a client sends is read on
its way to the field. */
int badhostname(const char *hostname){
const unsigned char *c;
if(!hostname) return 1;
for(c = (const unsigned char *)hostname; *c; c++)
if(*c <= ' ' || *c == 0x7f) return 1;
return 0;
}
int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
char *sp=NULL,*se=NULL;
int ret = 0;
if(!hostname || !*hostname)return 2;
if(badhostname(hostname)) return 1;
if(*hostname == '[') se=strchr(hostname, ']');
if ((sp = strchr(se?se:hostname, ':'))) {
if(strchr(sp+1, ':'))sp = NULL;