File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 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) {
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
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