Avoid segfault with malformed IPv6 address

A literal IPv6 address without a trailing bracket will result in a write
past the end of the address buffer:

~~~ segfault.conf
protocols:
(
 { name: "tls"; host: "["; port: "8443"; }
);
~~~

~~~
$ sslh-select -p 127.0.0.1:443 --foreground -F./segfault.conf
[: no closing bracket in IPv6 address?
Segmentation fault (core dumped)
~~~
This commit is contained in:
Michael Santos 2018-06-17 10:01:44 -04:00
parent c179d9a57b
commit 5cf591a254

View File

@ -496,6 +496,7 @@ int resolve_split_name(struct addrinfo **out, const char* ct_host, const char* s
end = strrchr(host, ']');
if (!end) {
fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host);
return -1;
}
host++; /* skip first bracket */
*end = 0; /* remove last bracket */