File tree 2 files changed +23
-0
lines changed 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1569,6 +1569,13 @@ function loadDocuments(input, options) {
1569
1569
1570
1570
var state = new State ( input , options ) ;
1571
1571
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
+
1572
1579
// Use 0 as string terminator. That significantly simplifies bounds check.
1573
1580
state . input += '\0' ;
1574
1581
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments