Skip to content

Commit

Permalink
Verify that there are no null-bytes in input
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Nov 4, 2019
1 parent aeb6828 commit 33c2236
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/js-yaml/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,13 @@ function loadDocuments(input, options) {

var state = new State(input, options);

var nullpos = input.indexOf('\0');

if (nullpos !== -1) {
state.position = nullpos;
throwError(state, 'null byte is not allowed in input');
}

// Use 0 as string terminator. That significantly simplifies bounds check.
state.input += '\0';

Expand Down
16 changes: 16 additions & 0 deletions test/issues/0525-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';


var assert = require('assert');
var yaml = require('../../');


test('Should throw if there is a null-byte in input', function () {
try {
yaml.safeLoad('foo\0bar');
} catch (err) {
assert(err.stack.startsWith('YAMLException: null byte is not allowed in input'));
return;
}
assert.fail(null, null, 'Expected an error to be thrown');
});

0 comments on commit 33c2236

Please sign in to comment.