From 195c21ab2eb3217e9a018dd928e06c201f00a791 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 18 Dec 2023 09:35:22 +0100 Subject: [PATCH] Avoid crashing on missing 'method' or 'path' headers in httpd_connection(). --- httpd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/httpd.c b/httpd.c index 3f4e9f0..197a6c0 100644 --- a/httpd.c +++ b/httpd.c @@ -245,8 +245,13 @@ void httpd_connection(FILE *f) return; } - method = xs_dict_get(req, "method"); - q_path = xs_dup(xs_dict_get(req, "path")); + if (!(method = xs_dict_get(req, "method")) || !(p = xs_dict_get(req, "path"))) { + /* missing needed headers; discard */ + fclose(f); + return; + } + + q_path = xs_dup(p); /* crop the q_path from leading / and the prefix */ if (xs_endswith(q_path, "/"))