Skip to content

Commit

Permalink
hcl: error if we scan a null char before end of input text
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
mitchellh committed Nov 22, 2016
1 parent c3e054b commit d02cd46
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ func TestDecode_interface(t *testing.T) {
},
},
},

{
"git_crypt.hcl",
true,
nil,
},
}

for _, tc := range cases {
Expand Down
4 changes: 4 additions & 0 deletions hcl/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ func TestParse(t *testing.T) {
"object_key_assign_without_value3.hcl",
true,
},
{
"git_crypt.hcl",
true,
},
}

const fixtureDir = "./test-fixtures"
Expand Down
Binary file added hcl/parser/test-fixtures/git_crypt.hcl
Binary file not shown.
6 changes: 6 additions & 0 deletions hcl/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added test-fixtures/git_crypt.hcl
Binary file not shown.

0 comments on commit d02cd46

Please sign in to comment.