pvorb/node-clone — pull request #15 by w1nk (2012-12-06 15:58:14+00:00)
Title: Properly clone node's Buffer class

Right now, the naive javascript copy clones the buffer pretty well, including it's prototypes. This gives the impression that the buffer has been properly cloned, and in most cases it may work. In my repo you'll find a branch with a file (example.tar.gz at: https://github.com/w1nk/node-clone/raw/testcase/example.tar.gz). If you modify server.js, you'll see where the options cloning is happening. If you pass the original options object into createServer you'll be prompted with your passphrase (password) and everything will funciton. If you pass the cloned object in, it'll never prompt you and silently fail. I've narrowed the issue down I believe into node_crypto.cc, in the LoadBIO function:

```C++
// Takes a string or buffer and loads it into a BIO.
// Caller responsible for BIO_free-ing the returned object.
static BIO* LoadBIO (Handle v) {
BIO *bio = BIO_new(BIO_s_mem());
if (!bio) return NULL;

HandleScope scope;

int r = -1;

if (v->IsString()) {
String::Utf8Value s(v);
r = BIO_write(bio, *s, s.length());
} else if (Buffer::HasInstance(v)) {
Local