Skip to content

Commit

Permalink
[Dotenv] Fixed infinite loop with missing quote followed by quoted value
Browse files Browse the repository at this point in the history
If there's a quote missing to end a value and in the next line there's again a quoted value Dotenv will run into an infinite loop. An .env file with the following content will result in this error:
```
FOO="foo
BAR="bar"
```
See #34642 for more details.
  • Loading branch information
stollr committed Jan 7, 2020
1 parent 4595330 commit 22577db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ private function lexValue()
$this->cursor += 1 + $len;
} elseif ('"' === $this->data[$this->cursor]) {
$value = '';
++$this->cursor;

if (++$this->cursor === $this->end) {
throw $this->createFormatException('Missing quote to end the value');
}

while ('"' !== $this->data[$this->cursor] || ('\\' === $this->data[$this->cursor - 1] && '\\' !== $this->data[$this->cursor - 2])) {
$value .= $this->data[$this->cursor];
Expand Down
1 change: 1 addition & 0 deletions Tests/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function getEnvDataWithFormatErrors()
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
["FOO=\"foo\nBAR=\"bar\"", "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo\\nBAR=\"bar\"...\n ^ line 1 offset 18"],
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 9"],
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
Expand Down

0 comments on commit 22577db

Please sign in to comment.