Created
August 5, 2010 20:46
-
-
Save bnoordhuis/510349 to your computer and use it in GitHub Desktop.
Reproduce SIGSEGV in Buffer::New(size_t)
This file contains hidden or 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
#include <v8.h> | |
#include <node.h> | |
#include <alloca.h> | |
#include <node_buffer.h> | |
using namespace v8; | |
using namespace node; | |
static Handle<Value> dummy(const Arguments& args) { | |
HandleScope scope; | |
size_t size = args[0]->ToUint32()->IntegerValue(); | |
char *p = (char *) alloca(size); *p = 0; // claim stack, touch so it doesn't get optimized away | |
Buffer *b = Buffer::New(size); | |
return b->handle_; | |
} | |
extern "C" void init(Handle<Object> target) { | |
HandleScope scope; | |
target->Set(String::NewSymbol("dummy"), FunctionTemplate::New(dummy)->GetFunction()); | |
} |
This file contains hidden or 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
require('./dummy').dummy(512 * 1024); // ok | |
require('./dummy').dummy(1024 * 1024); // dies with SIGSEGV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment