Skip to content
Browse files

fix segfault when passing null or undefined to bigint constructor

fix tests
  • Loading branch information...
1 parent cc31d24 commit 2690309d28ad5101ec3dfc7e0880e18ea98a0a2d @vadimg vadimg committed Sep 1, 2011
Showing with 11 additions and 3 deletions.
  1. +4 −0 bigint.cc
  2. +2 −1 package.json
  3. +3 −0 test/big.js
  4. +2 −2 test/seed.js
View
4 bigint.cc
@@ -231,6 +231,10 @@ BigInt::New(const Arguments& args)
}
Local<Value> obj = js_conditioner->Call(ctx, args.Length(), newArgs);
+ if(!*obj) {
+ return ThrowException(Exception::Error(String::New("Invalid type passed to bigint constructor")));
+ }
+
String::Utf8Value str(obj->ToObject()->Get(String::NewSymbol("num"))->ToString());
base = obj->ToObject()->Get(String::NewSymbol("base"))->ToNumber()->Value();
View
3 package.json
@@ -24,7 +24,8 @@
},
"devDependencies" : {
"expresso" : ">=0.6.0",
- "binary" : ">=0.1.7"
+ "binary" : ">=0.1.7",
+ "put" : ">=0.0.5"
},
"scripts" : {
"test" : "expresso"
View
3 test/big.js
@@ -20,6 +20,9 @@ exports.create = function () {
}
assert.eql(bigint('1.23e-45').toString(), '0');
+
+ assert.throws(function() { bigint(undefined); });
+ assert.throws(function() { bigint(null); });
};
exports.add = function () {
View
4 test/seed.js
@@ -6,9 +6,9 @@ exports.rand = function () {
assert.fail('never executed');
}, 5000);
- var cmd = 'node -e \'require('
+ var cmd = 'node -e \'console.log(require('
+ JSON.stringify(__dirname + '/../')
- + ').rand(1000).toString()\''
+ + ').rand(1000).toString())\''
;
exec(cmd, function (err1, r1) {
exec(cmd, function (err2, r2) {

0 comments on commit 2690309

Please sign in to comment.
Something went wrong with that request. Please try again.