Skip to content

Crash in js_error::init when err_message is null #603

@spencerbryson

Description

@spencerbryson

Describe the bug
js_error::init does not properly handle the case when ToCStringCopy(err_message) returns null (e.g. err_message is null), leading to a crash on this line.

To Reproduce
Steps to reproduce the behavior:

  • Infinite recursion scenario can reliably reproduce the issue.
CREATE EXTENSION plv8;

CREATE OR REPLACE FUNCTION infinite_recursion(counter integer DEFAULT 0)
RETURNS void AS $$
  plv8.elog(NOTICE, counter);
  plv8.execute('SELECT infinite_recursion($1)', [counter + 1]);
$$ LANGUAGE plv8;

SELECT infinite_recursion();

Expected behavior
We should not be crashing during error handling.

Version Information:
Tested on earlier version, but latest should be impacted as well.

  • PLV8 Version: 3.1.10
  • Postgres Version 17.6

Additional context
Minimal fix could be as simple as assigning "unknown exception" if the msg is null.

--- a/plv8.cc
--
  |   | +++ b/plv8.cc
  |   | @@ -2395,83 +2395,112 @@ js_error::init(Isolate *isolate, v8::Local<v8::Value> exception, v8::Local<Messa
  |   |  
  |   | try
  |   | {
  |   | -		m_msg = ToCStringCopy(err_message);

  |   | +		char* msg = ToCStringCopy(err_message);
  |   | +		m_msg = msg ? msg : pstrdup("unknown exception");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions