Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
node: don't scan add-on for "init" symbol
Browse files Browse the repository at this point in the history
From this commit onwards, use of the NODE_MODULE macro is mandatory. This lets
node guard against modules that are ABI incompatible.
  • Loading branch information
bnoordhuis committed Jul 26, 2012
1 parent c3d4c35 commit f692347
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/node.cc
Expand Up @@ -1690,7 +1690,6 @@ Handle<Value> 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) {
Expand Down Expand Up @@ -1744,27 +1743,20 @@ Handle<Value> 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<void**>(&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<void**>(&mod->register_func))) {
Local<String> 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<Value> 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
Expand Down

0 comments on commit f692347

Please sign in to comment.