From e6ebc658333082c50d109cd2ae7b55eb1ab184e9 Mon Sep 17 00:00:00 2001 From: vamsi Date: Thu, 26 Mar 2026 17:10:35 +0530 Subject: [PATCH] Fix syntax crash from null filter When a filter or validate function throws null, the global event loop in loop.js unsafely tries to access its properties, crashing couchjs. This adds safe null checks to the global handler to prevent complete denial of service. --- share/server/loop.js | 4 ++++ share/server/validate.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/share/server/loop.js b/share/server/loop.js index 1a5cab843c2..b45806ac51a 100644 --- a/share/server/loop.js +++ b/share/server/loop.js @@ -135,6 +135,10 @@ var Loop = function() { "rereduce" : Views.rereduce }; function handleError(e) { + if (e == null) { + respond(["error", "unnamed_error", String(e)]); + return; + } var type = e[0]; if (type == "fatal") { e[0] = "error"; // we tell the client it was a fatal error by dying diff --git a/share/server/validate.js b/share/server/validate.js index 5b50e54732f..832ee38abe7 100644 --- a/share/server/validate.js +++ b/share/server/validate.js @@ -16,7 +16,7 @@ var Validate = { fun.apply(ddoc, args); respond(1); } catch (error) { - if (error.name && error.stack) { + if (error && error.name && error.stack) { throw error; } respond(error);