~sircmpwn/gmni-devel

gmnisrv: serve: make hostname matching case-insensitive v1 PROPOSED

William Casarin: 1
 serve: make hostname matching case-insensitive

 1 files changed, 14 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/gmni-devel/patches/26529/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gmnisrv] serve: make hostname matching case-insensitive Export this patch

Reported-by: James Tomasino <james@tomasino.org>
---
 src/serve.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/serve.c b/src/serve.c
index bcbef5c..c7cc505 100644
--- a/src/serve.c
+++ b/src/serve.c
@@ -1,5 +1,6 @@
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -602,6 +603,18 @@ serve_request(struct gmnisrv_client *client)
	client_submit_response(client, GEMINI_STATUS_SUCCESS, meta, body);
}

static int
stricmp(const char *a, const char *b)
{
	int d;

	for (;; a++, b++) {
		d = tolower(*a) - tolower(*b);
		if (d != 0 || !*a)
			return d;
	}
}

bool
request_validate(struct gmnisrv_client *client, char **path)
{
@@ -637,7 +650,7 @@ request_validate(struct gmnisrv_client *client, char **path)
		client_submit_response(client,
			GEMINI_STATUS_BAD_REQUEST, error, NULL);
		goto exit;
	} else if (strcmp(part, client->host->hostname) != 0) {
	} else if (stricmp(part, client->host->hostname) != 0) {
		free(part);
		const char *error = "Protocol error: hostname does not match SNI";
		client_submit_response(client,
-- 
2.32.0
I don't think I need stricmp here, looks like there's a strcasecmp
function in strings.h? will redo in v2