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");
Describe the bug
js_error::initdoes not properly handle the case whenToCStringCopy(err_message)returns null (e.g.err_messageis null), leading to a crash on this line.To Reproduce
Steps to reproduce the behavior:
Expected behavior
We should not be crashing during error handling.
Version Information:
Tested on earlier version, but latest should be impacted as well.
Additional context
Minimal fix could be as simple as assigning "unknown exception" if the msg is null.