Fix view server crash when map/reduce function throws null#5944
Open
vamsi2246 wants to merge 1 commit intoapache:mainfrom
Open
Fix view server crash when map/reduce function throws null#5944vamsi2246 wants to merge 1 commit intoapache:mainfrom
vamsi2246 wants to merge 1 commit intoapache:mainfrom
Conversation
When a map or reduce function throws null or undefined, the JavaScript view server's error handlers crash while attempting to stringify or access properties on the null exception. This patch adds safe null checks to these critical property accesses, allowing the view server to correctly log the exception and proceed without crashing the entire OS process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR fixes a critical bug where the JavaScript view server crashes if a user-defined map or reduce function throws
nullorundefined.Details
When a
mapfunction executesthrow null;, the resulting error caught byviews.jsisnull. ThehandleViewErrorfunction attempts to checkif (err[0] == "fatal"), which immediately throws aTypeError: Cannot read properties of null (reading '0'). Because this occurs inside the uncaught error handler, it crashes the entirecouchjsOS process, failing the view query completely.The same vulnerability exists inside
errstr(util.js) which unsafely checkse.toSource.This patch adds safe null checks to these critical property accesses, allowing the view server to correctly log the
nullexception and proceed without crashing.