Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-9878 Add type checks to V8 C++ bindings
The main focus of this ticket is tightening up input validation in our V8 bindings. Doing this required normalizing the way we create custom types in JS that have special C++-driven behavior. All special types now use FunctionTemplates that are attached to the V8Scope object. This allows us to test if an object is of the correct type before using it. Other related tickets partially addressed: SERVER-8961 Differences in argument validation of custom types between v8 and Spidermonkey SERVER-9803 Handle regular expression parse errors without seg faulting
- Loading branch information
1 parent
c676251
commit fda4a23
Showing
7 changed files
with
752 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Make sure we only make a DBRef object for objects where the first field is a string named $ref | ||
// and the second field is $id with any type. Only the first two fields matter for deciding if it | ||
// is a DBRef. See http://docs.mongodb.org/manual/reference/database-references/#dbrefs. | ||
|
||
var t = db.dbref3 | ||
|
||
// true cases | ||
t.insert({sub: {$ref: "foo", $id: "bar"}, dbref: true}); | ||
t.insert({sub: {$ref: "foo", $id: "bar", $db: "baz"}, dbref: true}); | ||
t.insert({sub: {$ref: "foo", $id: "bar", db: "baz"}, dbref: true}); // out of spec but accepted | ||
t.insert({sub: {$ref: "foo", $id: ObjectId()}, dbref: true}); | ||
t.insert({sub: {$ref: "foo", $id: 1}, dbref: true}); | ||
|
||
t.insert({sub: {$ref: 123/*not a string*/, $id: "bar"}, dbref: false}); | ||
t.insert({sub: {$id: "bar", $ref: "foo"}, dbref: false}); | ||
t.insert({sub: {$ref: "foo"}, dbref: false}); | ||
t.insert({sub: {$id: "foo"}, dbref: false}); | ||
t.insert({sub: {other: 1, $ref: "foo", $id: "bar"}, dbref: false}); | ||
|
||
t.find().forEach(function(obj) { | ||
assert.eq(obj.sub.constructor == DBRef, obj.dbref, tojson(obj)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.