aboutsummaryrefslogtreecommitdiff
path: root/gmid.h
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2024-08-23 10:22:31 +0000
committerOmar Polo <op@omarpolo.com>2024-08-23 10:22:31 +0000
commit2f57c36f2f31fd95c6048a0efcfdd1da79d6e30c (patch)
tree3d3f0e8cc9f693ef461fc229f04cbcd0b07bd5be /gmid.h
parent2922e3f14f02dfd00440e5b528fb7c38dab81050 (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>.
Diffstat (limited to 'gmid.h')
-rw-r--r--gmid.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/gmid.h b/gmid.h
index d68e0e3..15f8622 100644
--- a/gmid.h
+++ b/gmid.h
@@ -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;