aws-cloudformation / aws-cloudformation/cfn-lint

Unsafe call to glob causes error if filename contains special characters

Open
#2,136 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.6k
Forks
643
Avg merge
1d 3h
Merged PRs (30d)
38

Description

*cfn-lint version: 0.54.1*

Given a CloudFormation template whose filename contains `[` and `]`, due to unsafe call to `glob.glob` the following is seen:

```
▶ cfn-lint emr/tests/__snapshots__/test_snapshot\[emr--tests--emr.template.2.yaml\].yaml
Traceback (most recent call last):
File "/Users/alexharvey/git/fox/streamotion-platform-sceptre/venv/bin/cfn-lint", line 8, in
sys.exit(main())
File "/Users/alexharvey/git/fox/streamotion-platform-sceptre/venv/lib/python3.8/site-packages/cfnlint/__main__.py", line 26, in main
(args, filenames, formatter) = cfnlint.core.get_args_filenames(sys.argv[1:])
File "/Users/alexharvey/git/fox/streamotion-platform-sceptre/venv/lib/python3.8/site-packages/cfnlint/core.py", line 177, in get_args_filenames
if not config.templates:
File "/Users/alexharvey/git/fox/streamotion-platform-sceptre/venv/lib/python3.8/site-packages/cfnlint/config.py", line 587, in templates
add_filenames = glob.glob(filename, recursive=True)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/glob.py", line 21, in glob
return list(iglob(pathname, recursive=recursive))
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/glob.py", line 74, in _iglob
for name in glob_in_dir(dirname, basename, dironly):
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/glob.py", line 85, in _glob1
return fnmatch.filter(names, pattern)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/fnmatch.py", line 52, in filter
match = _compile_pattern(pat)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/fnmatch.py", line 46, in _compile_pattern
return re.compile(res).match
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/re.py", line 252, in compile
return _compile(pattern, flags)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/re.py", line 304, in _compile
p = sre_compile.compile(pattern, flags)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/sre_parse.py", line 948, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/sre_parse.py", line 443, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/sre_parse.py", line 834, in _parse
p = _parse_sub(source, state, sub_verbose, nested + 1)
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/sre_parse.py", line 443, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "/Users/alexharvey/.pyenv/versions/3.8.9/lib/python3.8/sre_parse.py", line 598, in _parse
raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range r-\- at position 20
```

Contributor guide

Open the contributing guide

Research direction

Start at cfnlint/config.py, specifically the templates property and get_args_filenames path shown in the traceback, and reproduce the failure with the provided filename containing [ and ]. Done means cfn-lint processes filenames containing these characters without raising the reported regular-expression error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cli, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.