diff --git a/src/http.cc b/src/http.cc index 1ffcf52cb63..fda19fe4cb7 100644 --- a/src/http.cc +++ b/src/http.cc @@ -231,10 +231,9 @@ HTTPConnection::on_body (http_parser *parser, const char *buf, size_t len) } argv[0] = array; } - on_body->Call(message_handler, 1, argv); TryCatch try_catch; - Local ret = on_body->Call(message_handler, 0, NULL); + Local ret = on_body->Call(message_handler, 1, argv); if (ret.IsEmpty()) { fatal_exception(try_catch); return -2; @@ -339,6 +338,8 @@ HTTPServer::OnConnection (struct sockaddr *addr, socklen_t len) HTTPConnection::server_constructor_template->GetFunction()->NewInstance(0, NULL); HTTPConnection *connection = NODE_UNWRAP(HTTPConnection, connection_handle); + if (!connection) return NULL; + connection->SetAcceptor(handle_); return connection; diff --git a/src/net.cc b/src/net.cc index 8c00dc15b53..40bafad0dd8 100644 --- a/src/net.cc +++ b/src/net.cc @@ -72,6 +72,8 @@ Handle Connection::EncodingGetter (Local _, const AccessorInfo& info) { Connection *connection = NODE_UNWRAP(Connection, info.This()); + if (!connection) return Handle(); + HandleScope scope; if (connection->encoding_ == UTF8) @@ -84,6 +86,8 @@ void Connection::EncodingSetter (Local _, Local value, const AccessorInfo& info) { Connection *connection = NODE_UNWRAP(Connection, info.This()); + if (!connection) return; + if (!value->IsString()) { connection->encoding_ = RAW; return; @@ -148,8 +152,10 @@ Connection::v8New (const Arguments& args) Handle Connection::v8Connect (const Arguments& args) { - HandleScope scope; Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + if (!connection) return Handle(); + + HandleScope scope; if (args.Length() == 0 || args[0]->IsInt32() == false) return ThrowException(String::New("Must specify a port.")); @@ -231,6 +237,8 @@ Connection::v8Close (const Arguments& args) { HandleScope scope; Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + if (!connection) return Handle(); + connection->Close(); return Undefined(); } @@ -240,6 +248,8 @@ Connection::v8FullClose (const Arguments& args) { HandleScope scope; Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + if (!connection) return Handle(); + connection->FullClose(); return Undefined(); } @@ -249,6 +259,8 @@ Connection::v8ForceClose (const Arguments& args) { HandleScope scope; Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + if (!connection) return Handle(); + connection->ForceClose(); //connection->Detach(); return Undefined(); @@ -260,6 +272,7 @@ Connection::v8Send (const Arguments& args) { HandleScope scope; Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + if (!connection) return Handle(); if (args[0]->IsString()) { // utf8 encoding @@ -321,7 +334,7 @@ Connection::OnReceive (const void *buf, size_t len) callback->Call(handle_, argc, argv); if (try_catch.HasCaught()) - fatal_exception(try_catch); // XXX is this the right action to take? + fatal_exception(try_catch); } #define DEFINE_SIMPLE_CALLBACK(name, symbol) \ @@ -331,7 +344,10 @@ void name () \ Local callback_v = handle_->Get(symbol); \ if (!callback_v->IsFunction()) return; \ Handle callback = Handle::Cast(callback_v); \ + TryCatch try_catch; \ callback->Call(handle_, 0, NULL); \ + if (try_catch.HasCaught()) \ + fatal_exception(try_catch); \ } DEFINE_SIMPLE_CALLBACK(Connection::OnConnect, ON_CONNECT_SYMBOL) @@ -397,6 +413,8 @@ Acceptor::OnConnection (struct sockaddr *addr, socklen_t len) Connection::constructor_template->GetFunction()->NewInstance(0, NULL); Connection *connection = NODE_UNWRAP(Connection, connection_handle); + if (!connection) return NULL; + connection->SetAcceptor(handle_); Handle argv[1] = { connection_handle }; @@ -436,6 +454,7 @@ Handle Acceptor::v8Listen (const Arguments& args) { Acceptor *acceptor = NODE_UNWRAP(Acceptor, args.Holder()); + if (!acceptor) return Handle(); if (args.Length() < 1) return ThrowException(String::New("Must give at least a port as argument.")); @@ -468,6 +487,8 @@ Handle Acceptor::v8Close (const Arguments& args) { Acceptor *acceptor = NODE_UNWRAP(Acceptor, args.Holder()); + if (!acceptor) return Handle(); + acceptor->Close(); return Undefined(); } diff --git a/src/node.cc b/src/node.cc index 5790ea12b3c..277717b54f4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -61,8 +61,16 @@ void* ObjectWrap::Unwrap (Handle handle) { HandleScope scope; - Handle field = - Handle::Cast(handle->GetInternalField(0)); + if(handle.IsEmpty() || handle->InternalFieldCount() == 0) { + ThrowException(String::New("Tried to unwrap object without internal field.")); + return NULL; + } + Local value = handle->GetInternalField(0); + if (value.IsEmpty()) { + ThrowException(String::New("Tried to unwrap object with empty internal field.")); + return NULL; + } + Handle field = Handle::Cast(value); return field->Value(); }