From 69e5c8dbfd0b3f23339c1802f150dfd6fe737239 Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Mon, 3 Jun 2019 15:38:29 +0300 Subject: [PATCH] httpd: Do not crash on empty-body POSTs --- lib/sliblist.c | 2 +- modules/httpd/httpd_proc.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/sliblist.c b/lib/sliblist.c index 7306a77d9c8..90370d99880 100644 --- a/lib/sliblist.c +++ b/lib/sliblist.c @@ -127,7 +127,7 @@ int slinkedl_traverse(slinkedl_list_t *list, void *slinkedl_peek(slinkedl_list_t *list) { - if (!list) + if (!list || !list->head) return NULL; return list->head->data; diff --git a/modules/httpd/httpd_proc.c b/modules/httpd/httpd_proc.c index bfc8c55f020..094cbf132e1 100644 --- a/modules/httpd/httpd_proc.c +++ b/modules/httpd/httpd_proc.c @@ -414,7 +414,7 @@ int answer_to_connection (void *cls, struct MHD_Connection *connection, str_str_t *kv; char *p; int ret_code = MHD_HTTP_OK; - str saved_body; + str saved_body = STR_NULL; #if ( MHD_VERSION >= 0x000092800 ) int sv_sockfd; @@ -485,7 +485,9 @@ int answer_to_connection (void *cls, struct MHD_Connection *connection, if (cb) { normalised_url = &url[cb->http_root->len+1]; LM_DBG("normalised_url=[%s]\n", normalised_url); - saved_body = ((str_str_t *)slinkedl_peek(pr->p_list))->val; + kv = slinkedl_peek(pr->p_list); + if (kv) + saved_body = ((str_str_t *)kv)->val; ret_code = cb->callback(cls, (void*)connection, normalised_url, method, version,