Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created August 5, 2010 20:46
Show Gist options
  • Save bnoordhuis/510349 to your computer and use it in GitHub Desktop.
Save bnoordhuis/510349 to your computer and use it in GitHub Desktop.
Reproduce SIGSEGV in Buffer::New(size_t)
#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());
}
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