Skip to content

Commit 33c2236

Browse files
committed
Verify that there are no null-bytes in input
1 parent aeb6828 commit 33c2236

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/js-yaml/loader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,13 @@ function loadDocuments(input, options) {
15691569

15701570
var state = new State(input, options);
15711571

1572+
var nullpos = input.indexOf('\0');
1573+
1574+
if (nullpos !== -1) {
1575+
state.position = nullpos;
1576+
throwError(state, 'null byte is not allowed in input');
1577+
}
1578+
15721579
// Use 0 as string terminator. That significantly simplifies bounds check.
15731580
state.input += '\0';
15741581

test/issues/0525-1.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
4+
var assert = require('assert');
5+
var yaml = require('../../');
6+
7+
8+
test('Should throw if there is a null-byte in input', function () {
9+
try {
10+
yaml.safeLoad('foo\0bar');
11+
} catch (err) {
12+
assert(err.stack.startsWith('YAMLException: null byte is not allowed in input'));
13+
return;
14+
}
15+
assert.fail(null, null, 'Expected an error to be thrown');
16+
});

0 commit comments

Comments
 (0)