Skip to content

Commit 593c9d4

Browse files
authored
bug: fix segfault of invalid toString() object (#1450)
* bug: verify toString() returns valid data * test: faulty toString test
1 parent 3fb3715 commit 593c9d4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/statement.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ template <class T> Values::Field*
205205
return new Values::Float(pos, source.ToNumber().DoubleValue());
206206
}
207207
else if (source.IsObject()) {
208-
std::string val = source.ToString().Utf8Value();
208+
Napi::String napiVal = source.ToString();
209+
// Check whether toString returned a value that is not undefined.
210+
if(napiVal.Type() == 0) {
211+
return NULL;
212+
}
213+
214+
std::string val = napiVal.Utf8Value();
209215
return new Values::Text(pos, val.length(), val.c_str());
210216
}
211217
else {

test/other_objects.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,13 @@ describe('data types', function() {
8686
});
8787
});
8888
});
89+
90+
it('should ignore faulty toString', function(done) {
91+
const faulty = { toString: 23 };
92+
db.run("INSERT INTO txt_table VALUES(?)", faulty, function (err) {
93+
assert.notEqual(err, undefined);
94+
done();
95+
});
96+
});
97+
8998
});

0 commit comments

Comments
 (0)