Skip to content

Commit

Permalink
cue/load: don't hang on files named -
Browse files Browse the repository at this point in the history
Note that the check is quite carefully placed to still allow
`cue eval -` to select stdin, even if the current directory
has a file named '-'.

Fixes #422

Change-Id: Ic60fa137f929a1102753f1f20a8c7a27728f121c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7263
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
mpvl committed Sep 30, 2020
1 parent e9286f0 commit 11b507c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/cue/cmd/testdata/script/no_read_stdin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# try to trick cue reading from a perpetually open stdin by placing a file
# named '-' in the current directory.

! cue eval
stdin -
cmp stderr expect-stderr
-- - --
-- expect-stderr --
no CUE files in .
5 changes: 5 additions & 0 deletions cue/load/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func (l *loader) importPkg(pos token.Pos, p *build.Instance) *build.Instance {
if f.IsDir() {
continue
}
if f.Name() == "-" {
if _, err := cfg.fileSystem.stat("-"); !os.IsNotExist(err) {
continue
}
}
file, err := filetypes.ParseFile(f.Name(), filetypes.Input)
if err != nil {
p.UnknownFiles = append(p.UnknownFiles, &build.File{
Expand Down

0 comments on commit 11b507c

Please sign in to comment.