Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fixed uninitialized buffer vulnerability in base64 methods. (https://hackerone.com/reports/321701) #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ base64.encode = function (unencoded) {
var encoded;

try {
encoded = new Buffer(unencoded || '').toString('base64');
encoded = new Buffer(unencoded ? String(unencoded) : '').toString('base64');
}
catch (ex) {
return null;
Expand All @@ -34,7 +34,7 @@ base64.decode = function (encoded) {
var decoded;

try {
decoded = new Buffer(encoded || '', 'base64').toString('utf8');
decoded = new Buffer(encoded ? String(encoded) : '', 'base64').toString('utf8');
}
catch (ex) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "utile",
"description": "A drop-in replacement for `util` with some additional advantageous functions",
"version": "0.3.0",
"version": "0.3.1",
"author": "Nodejitsu Inc. <[email protected]>",
"maintainers": [
"indexzero <[email protected]>"
Expand Down
17 changes: 17 additions & 0 deletions test/base64-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var assert = require('assert'),
vows = require('vows'),
utile = require('../lib/');


vows.describe('utile/base64').addBatch({

'Should treat input as a string for encode().': function() {
assert.equal(utile.base64.encode('200'), utile.base64.encode(200))
assert.equal(utile.base64.encode('100000000'), utile.base64.encode(1e8))
},

'Should treat input as a string for decode().': function() {
assert.equal(utile.base64.decode('MTAw'), 100)
}

}).export(module);