diff options
author | Omar Polo <op@omarpolo.com> | 2024-08-23 10:22:31 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-08-23 10:22:31 +0000 |
commit | 2f57c36f2f31fd95c6048a0efcfdd1da79d6e30c (patch) | |
tree | 3d3f0e8cc9f693ef461fc229f04cbcd0b07bd5be | |
parent | 2922e3f14f02dfd00440e5b528fb7c38dab81050 (diff) |
work around comically tiny HOST_NAME_MAX on glibc system
glibc is clearly violating POSIX since they set HOST_NAME_MAX to 64, and
they've known so for years. Unfortunately this means that, despite
using the right interfaces, we have to work around bugs in their libc.
ugh.
Luckily, gmid doesn't need to do DNS, it just needs a define large
enough to store a hostname, but not unlimited, to catch possible
misconfigurations. We don't risk to round-trip this into an interface
that expects smaller strings.
Reported and fix tested by Anna “CyberTailor”,
see <https://codeberg.org/op/gmid/issues/3>.
-rwxr-xr-x | configure | 8 | ||||
-rw-r--r-- | gmid.h | 19 | ||||
-rwxr-xr-x | regress/regress | 1 | ||||
-rw-r--r-- | regress/tests.sh | 9 |
4 files changed, 24 insertions, 13 deletions
@@ -644,14 +644,6 @@ cat <<__HEREDOC__ # define LOGIN_NAME_MAX 32 # endif #endif - -#ifndef HOST_NAME_MAX -# if defined(_POSIX_HOST_NAME_MAX) -# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX -# else -# define HOST_NAME_MAX 255 -# endif -#endif __HEREDOC__ echo "file config.h: written" 1>&2 @@ -86,6 +86,15 @@ #define TLS_CERT_HASH_SIZE 128 +/* + * glibc is violating POSIX by defining HOST_NAME_MAX to a ridicully + * small value, so we can't use it. Luckily, we don't have to do DNS + * so we don't risk to pass buffers too big to functions that might + * not expect them, we just need a fixed size buffer to catch possible + * misconfigurations. + */ +#define GMID_HOST_NAME_MAX 255 /* without NUL */ + /* forward declaration */ struct privsep; struct privsep_proc; @@ -144,19 +153,19 @@ struct envlist { TAILQ_HEAD(aliashead, alist); struct alist { - char alias[HOST_NAME_MAX + 1]; + char alias[GMID_HOST_NAME_MAX + 1]; TAILQ_ENTRY(alist) aliases; }; TAILQ_HEAD(proxyhead, proxy); struct proxy { char match_proto[32]; - char match_host[HOST_NAME_MAX + 1]; + char match_host[GMID_HOST_NAME_MAX + 1]; char match_port[32]; - char host[HOST_NAME_MAX + 1]; + char host[GMID_HOST_NAME_MAX + 1]; char port[32]; - char sni[HOST_NAME_MAX]; + char sni[GMID_HOST_NAME_MAX]; int notls; uint32_t protocols; int noverifyname; @@ -199,7 +208,7 @@ struct location { TAILQ_HEAD(vhosthead, vhost); struct vhost { - char domain[HOST_NAME_MAX + 1]; + char domain[GMID_HOST_NAME_MAX + 1]; char *cert_path; char *key_path; char *ocsp_path; diff --git a/regress/regress b/regress/regress index c3bbed8..1d14644 100755 --- a/regress/regress +++ b/regress/regress @@ -40,6 +40,7 @@ run_test test_gemexp # Run regression tests for the gmid binary. run_test test_static_files +run_test test_alias_long_hostname run_test test_directory_redirect run_test test_serve_big_files run_test test_dont_execute_scripts diff --git a/regress/tests.sh b/regress/tests.sh index 0e07d19..4d89c2d 100644 --- a/regress/tests.sh +++ b/regress/tests.sh @@ -90,6 +90,15 @@ test_static_files() { check_reply "20 text/gemini" "# hello world" || return 1 } +test_alias_long_hostname() { + setup_simple_test '' ' +alias "laYkH0yyd7xDFO152Ubtm9Efxg8Gvt7wssNd8pPTVIIXVYbYrZERl38LrVY30WbrMrZxLFfhnmsfe1X2FUNAGMVYAxPspjl4" +' + + fetch / + check_reply "20 text/gemini" "# hello world" || return 1 +} + test_directory_redirect() { setup_simple_test |