Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions test/other_objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

});