hcl: error if we scan a null char before end of input text

This was allowing very strange input to be allowed through to Terraform
since some encryped output will contain null characters (such as from
git crypt).
This commit is contained in:
Mitchell Hashimoto 2016-11-21 18:08:30 -08:00
parent c3e054bfd4
commit d02cd46b72
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
5 changed files with 16 additions and 0 deletions

View File

@ -379,6 +379,12 @@ func TestDecode_interface(t *testing.T) {
},
},
},
{
"git_crypt.hcl",
true,
nil,
},
}
for _, tc := range cases {

View File

@ -504,6 +504,10 @@ func TestParse(t *testing.T) {
"object_key_assign_without_value3.hcl",
true,
},
{
"git_crypt.hcl",
true,
},
}
const fixtureDir = "./test-fixtures"

Binary file not shown.

View File

@ -95,6 +95,12 @@ func (s *Scanner) next() rune {
s.srcPos.Column = 0
}
// If we see a null character with data left, then that is an error
if ch == '\x00' && s.buf.Len() > 0 {
s.err("unexpected null character (0x00)")
return eof
}
// debug
// fmt.Printf("ch: %q, offset:column: %d:%d\n", ch, s.srcPos.Offset, s.srcPos.Column)
return ch

BIN
test-fixtures/git_crypt.hcl Normal file

Binary file not shown.