mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
crypto: don't assert when calling Cipher#final() twice
Remove the assert() that triggered when Cipher#final() or Decipher#final() was called twice. Fixes #4886.
This commit is contained in:
1 parent
be770a3839
commit
7189b3ed33
2 files changed
+15
-9
No files matched your search
+2
-9
@@ -2301,11 +2301,7 @@ class Cipher : public ObjectWrap {
|
||||
|
||||
int r = cipher->CipherFinal(&out_value, &out_len);
|
||||
|
||||
assert(out_value != NULL);
|
||||
assert(out_len != -1 || r == 0);
|
||||
|
||||
if (out_len == 0 || r == 0) {
|
||||
// out_value always get allocated.
|
||||
if (out_len <= 0 || r == 0) {
|
||||
delete[] out_value;
|
||||
if (r == 0) {
|
||||
Local<Value> exception = Exception::TypeError(
|
||||
@@ -2756,10 +2752,7 @@ class Decipher : public ObjectWrap {
|
||||
|
||||
int r = cipher->DecipherFinal<TOLERATE_PADDING>(&out_value, &out_len);
|
||||
|
||||
assert(out_value != NULL);
|
||||
assert(out_len != -1);
|
||||
|
||||
if (out_len == 0 || r == 0) {
|
||||
if (out_len <= 0 || r == 0) {
|
||||
delete [] out_value; // allocated even if out_len == 0
|
||||
if (r == 0) {
|
||||
Local<Value> exception = Exception::TypeError(
|
||||
|
||||
@@ -665,3 +665,16 @@ crypto.pbkdf2('pass\0word', 'sa\0lt', 4096, 16, function(err, result) {
|
||||
assert.throws(function() {
|
||||
crypto.pbkdf2('password', 'salt', 1, 20, null);
|
||||
});
|
||||
|
||||
// Calling Cipher.final() or Decipher.final() twice should error but
|
||||
// not assert. See #4886.
|
||||
(function() {
|
||||
var c = crypto.createCipher('aes-256-cbc', 'secret');
|
||||
try { c.final('xxx') } catch (e) { /* Ignore. */ }
|
||||
try { c.final('xxx') } catch (e) { /* Ignore. */ }
|
||||
try { c.final('xxx') } catch (e) { /* Ignore. */ }
|
||||
var d = crypto.createDecipher('aes-256-cbc', 'secret');
|
||||
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
||||
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
||||
try { d.final('xxx') } catch (e) { /* Ignore. */ }
|
||||
})();
|
||||
Reference in new issue
Block a user