mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 10:12:29 +08:00 
			
		
		
		
	caddyfile: Fix case where heredoc marker is empty after newline (#5769)
Fixes `panic: runtime error: slice bounds out of range [:3] with capacity 2` Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
		@ -154,6 +154,10 @@ func (l *lexer) next() (bool, error) {
 | 
				
			|||||||
			// we reset the val because the heredoc is syntax we don't
 | 
								// we reset the val because the heredoc is syntax we don't
 | 
				
			||||||
			// want to keep.
 | 
								// want to keep.
 | 
				
			||||||
			if ch == '\n' {
 | 
								if ch == '\n' {
 | 
				
			||||||
 | 
									if len(val) == 2 {
 | 
				
			||||||
 | 
										return false, fmt.Errorf("missing opening heredoc marker on line #%d; must contain only alpha-numeric characters, dashes and underscores; got empty string", l.line)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// check if there's too many <
 | 
									// check if there's too many <
 | 
				
			||||||
				if string(val[:3]) == "<<<" {
 | 
									if string(val[:3]) == "<<<" {
 | 
				
			||||||
					return false, fmt.Errorf("too many '<' for heredoc on line #%d; only use two, for example <<END", l.line)
 | 
										return false, fmt.Errorf("too many '<' for heredoc on line #%d; only use two, for example <<END", l.line)
 | 
				
			||||||
 | 
				
			|||||||
@ -409,6 +409,11 @@ EOF same-line-arg
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								input:        []byte("not-a-heredoc <<\n"),
 | 
				
			||||||
 | 
								expectErr:    true,
 | 
				
			||||||
 | 
								errorMessage: "missing opening heredoc marker on line #1; must contain only alpha-numeric characters, dashes and underscores; got empty string",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			input: []byte(`heredoc <<<EOF
 | 
								input: []byte(`heredoc <<<EOF
 | 
				
			||||||
	content
 | 
						content
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user