Check return value of config_setting_get_string_elem() for error
before passing the result to strlen():
~~~ segfault.conf
protocols:
(
{ name: "tls"; host: "localhost"; port: "8443"; sni_hostnames: [ 0 ];
}
);
~~~
in_socket may be used uninitialized if no addresses are available.
~~~
sslh-select.c:415:8: warning: Function call argument is an uninitialized value
check_access_rights(in_socket, cnx[i].proto->service)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
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)
~~~
Do not allocate a 0 byte buffer if no addresses are available:
common.c:122:14: warning: Call to 'malloc' has an allocation size of 0 bytes
*sockfd = malloc(num_addr * sizeof(*sockfd[0]));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~