diff --git a/deps/v8/src/platform-solaris.cc b/deps/v8/src/platform-solaris.cc index 4248ea214f..07718fe50b 100644 --- a/deps/v8/src/platform-solaris.cc +++ b/deps/v8/src/platform-solaris.cc @@ -125,12 +125,8 @@ const char* OS::LocalTimezone(double time) { double OS::LocalTimeOffset() { - // On Solaris, struct tm does not contain a tm_gmtoff field. - time_t utc = time(NULL); - ASSERT(utc != -1); - struct tm* loc = localtime(&utc); - ASSERT(loc != NULL); - return static_cast((mktime(loc) - utc) * msPerSecond); + tzset(); + return -static_cast(timezone * msPerSecond); } diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 18ef53073a..f026bb13f6 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4101,22 +4101,16 @@ class DiffieHellman : public ObjectWrap { int size = DH_compute_key(reinterpret_cast(data), key, diffieHellman->dh); - BN_free(key); - - Local outString; - - // DH_size returns number of bytes in a prime number - // DH_compute_key returns number of bytes in a remainder of exponent, which - // may have less bytes than a prime number. Therefore add 0-padding to the - // allocated buffer. - if (size != dataSize) { - assert(dataSize > size); - memset(data + size, 0, dataSize - size); - } if (size == -1) { int checkResult; - if (!DH_check_pub_key(diffieHellman->dh, key, &checkResult)) { + int checked; + + checked = DH_check_pub_key(diffieHellman->dh, key, &checkResult); + BN_free(key); + delete[] data; + + if (!checked) { return ThrowException(Exception::Error(String::New("Invalid key"))); } else if (checkResult) { if (checkResult & DH_CHECK_PUBKEY_TOO_SMALL) { @@ -4131,14 +4125,28 @@ class DiffieHellman : public ObjectWrap { } else { return ThrowException(Exception::Error(String::New("Invalid key"))); } + } + + BN_free(key); + assert(size >= 0); + + // DH_size returns number of bytes in a prime number + // DH_compute_key returns number of bytes in a remainder of exponent, which + // may have less bytes than a prime number. Therefore add 0-padding to the + // allocated buffer. + if (size != dataSize) { + assert(dataSize > size); + memset(data + size, 0, dataSize - size); + } + + Local outString; + + if (args.Length() > 2 && args[2]->IsString()) { + outString = EncodeWithEncoding(args[2], data, dataSize); + } else if (args.Length() > 1 && args[1]->IsString()) { + outString = EncodeWithEncoding(args[1], data, dataSize); } else { - if (args.Length() > 2 && args[2]->IsString()) { - outString = EncodeWithEncoding(args[2], data, dataSize); - } else if (args.Length() > 1 && args[1]->IsString()) { - outString = EncodeWithEncoding(args[1], data, dataSize); - } else { - outString = Encode(data, dataSize, BINARY); - } + outString = Encode(data, dataSize, BINARY); } delete[] data; diff --git a/src/v8_typed_array.cc b/src/v8_typed_array.cc index 64045ff776..8885f412ff 100644 --- a/src/v8_typed_array.cc +++ b/src/v8_typed_array.cc @@ -449,7 +449,7 @@ v8::Handle cTypeToValue(unsigned char val) { } template <> -v8::Handle cTypeToValue(char val) { +v8::Handle cTypeToValue(signed char val) { return v8::Integer::New(val); } @@ -495,7 +495,7 @@ unsigned char valueToCType(v8::Handle value) { } template <> -char valueToCType(v8::Handle value) { +signed char valueToCType(v8::Handle value) { return value->Int32Value(); } @@ -709,7 +709,7 @@ class DataView { } static v8::Handle getInt8(const v8::Arguments& args) { - return getGeneric(args); + return getGeneric(args); } static v8::Handle getUint16(const v8::Arguments& args) { @@ -741,7 +741,7 @@ class DataView { } static v8::Handle setInt8(const v8::Arguments& args) { - return setGeneric(args); + return setGeneric(args); } static v8::Handle setUint16(const v8::Arguments& args) { diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 5428aa0ce5..bbc35ef36c 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -563,6 +563,10 @@ var secret3 = dh3.computeSecret(key2, 'hex', 'base64'); assert.equal(secret1, secret3); +assert.throws(function() { + dh3.computeSecret(''); +}, /key is too small/i); + // https://github.com/joyent/node/issues/2338 assert.throws(function() { var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + diff --git a/test/simple/test-typed-arrays.js b/test/simple/test-typed-arrays.js index 803f18a729..00bf613543 100644 --- a/test/simple/test-typed-arrays.js +++ b/test/simple/test-typed-arrays.js @@ -174,3 +174,11 @@ uint8c.set(1, 260); assert.equal(uint8c[0], 0); assert.equal(uint8c[1], 255); + +(function() { + var numbers = []; + for (var i = 128; i <= 255; ++i) numbers.push(i); + var array = new Uint8Array(numbers); + var view = new DataView(array.buffer); + for (var i = 128; i <= 255; ++i) assert.equal(view.getInt8(i - 128), i - 256); +})();