Unverified Commit 593c9d49 by Kewde Committed by GitHub

bug: fix segfault of invalid toString() object (#1450)

* bug: verify toString() returns valid data
* test: faulty toString test
parent 3fb3715c
......@@ -205,7 +205,13 @@ template <class T> Values::Field*
return new Values::Float(pos, source.ToNumber().DoubleValue());
}
else if (source.IsObject()) {
std::string val = source.ToString().Utf8Value();
Napi::String napiVal = source.ToString();
// Check whether toString returned a value that is not undefined.
if(napiVal.Type() == 0) {
return NULL;
}
std::string val = napiVal.Utf8Value();
return new Values::Text(pos, val.length(), val.c_str());
}
else {
......
......@@ -86,4 +86,13 @@ describe('data types', function() {
});
});
});
it('should ignore faulty toString', function(done) {
const faulty = { toString: 23 };
db.run("INSERT INTO txt_table VALUES(?)", faulty, function (err) {
assert.notEqual(err, undefined);
done();
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment