From f69234703f7b6aab71f312205fa2a269f7bbbdd1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 27 Jul 2012 01:06:12 +0200 Subject: [PATCH] node: don't scan add-on for "init" symbol From this commit onwards, use of the NODE_MODULE macro is mandatory. This lets node guard against modules that are ABI incompatible. --- src/node.cc | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/node.cc b/src/node.cc index db3423c9abe..770d6d0785d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1690,7 +1690,6 @@ Handle DLOpen(const v8::Arguments& args) { HandleScope scope; char symbol[1024], *base, *pos; uv_lib_t lib; - node_module_struct compat_mod; int r; if (args.Length() < 2) { @@ -1744,27 +1743,20 @@ Handle DLOpen(const v8::Arguments& args) { return ThrowException(exception); } - // Get the init() function from the dynamically shared object. node_module_struct *mod; if (uv_dlsym(&lib, symbol, reinterpret_cast(&mod))) { - /* Start Compatibility hack: Remove once everyone is using NODE_MODULE macro */ - memset(&compat_mod, 0, sizeof compat_mod); - - mod = &compat_mod; - mod->version = NODE_MODULE_VERSION; - - if (uv_dlsym(&lib, "init", reinterpret_cast(&mod->register_func))) { - Local errmsg = String::New(uv_dlerror(&lib)); - uv_dlclose(&lib); - return ThrowException(Exception::Error(errmsg)); - } - /* End Compatibility hack */ + char errmsg[1024]; + snprintf(errmsg, sizeof(errmsg), "Symbol %s not found.", symbol); + return ThrowError(errmsg); } if (mod->version != NODE_MODULE_VERSION) { - Local exception = Exception::Error( - String::New("Module version mismatch, refusing to load.")); - return ThrowException(exception); + char errmsg[1024]; + snprintf(errmsg, + sizeof(errmsg), + "Module version mismatch. Expected %d, got %d.", + NODE_MODULE_VERSION, mod->version); + return ThrowError(errmsg); } // Execute the C++ module