From 0ab1c7ef7683e2b58472d4ea2b826c085fda1d97 Mon Sep 17 00:00:00 2001
From: Dmitry Frank <mail@dmitryfrank.com>
Date: Fri, 2 Feb 2018 00:30:27 +0200
Subject: [PATCH] Fail if passed a NULL handler

Before it resulted in an endless recursion.

Resolves https://github.com/cesanta/mongoose/issues/871

CL: Mongoose Web Server: Fail if passed a NULL handler to `mg_bind` or `mg_bind_opt`.

PUBLISHED_FROM=376e5d330a643fa530f6a27a422a1500f986c721
---
 mongoose.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mongoose.c b/mongoose.c
index 74adbb5d7..e47801bbd 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -3046,6 +3046,11 @@ struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
   opts.user_data = user_data;
 #endif
 
+  if (callback == NULL) {
+    MG_SET_PTRPTR(opts.error_string, "handler is required");
+    return NULL;
+  }
+
   MG_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);
 
 #if MG_ENABLE_TUN
-- 
GitLab