Skip to content

Commit a894708

Browse files
committed
Adding input checking
1 parent d5187bf commit a894708

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

nodejs/ece.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ function encryptRecord(key, counter, buffer, pad, padSize) {
265265
* crypto.createDiffieHellman()).
266266
*/
267267
function encrypt(buffer, params) {
268+
if (!Buffer.isBuffer(buffer)) {
269+
throw new Error('buffer argument must be a Buffer');
270+
}
268271
var key = deriveKeyAndNonce(params, MODE_ENCRYPT);
269272
var rs = determineRecordSize(params);
270273
var start = 0;

nodejs/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ function logbuf(msg, buf) {
3232
}
3333
}
3434

35+
function validate() {
36+
['hello', null, 1, NaN, [], {}].forEach(function(v) {
37+
try {
38+
encrypt('hello', {});
39+
throw new Error('should insist on a buffer');
40+
} catch (e) {}
41+
});
42+
}
43+
3544
function encryptDecrypt(length, encryptParams, decryptParams) {
3645
decryptParams = decryptParams || encryptParams;
3746
logbuf('Salt', encryptParams.salt);
@@ -155,6 +164,7 @@ function useDH() {
155164
encryptDecrypt(length.readUInt16BE(2), encryptParams, decryptParams);
156165
}
157166

167+
validate();
158168
var i;
159169
for (i = 0; i < count; ++i) {
160170
[ useExplicitKey,

0 commit comments

Comments
 (0)