Skip to content

Commit

Permalink
Merge pull request moby#5146 from kariya-mitsuru/check-invalid-env-re…
Browse files Browse the repository at this point in the history
…placement

Check invalid environment replacement form like ${VAR:%}
  • Loading branch information
tonistiigi authored Aug 12, 2024
2 parents d1e6c91 + 9749c52 commit add7328
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontend/dockerfile/shell/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ func (sw *shellWord) processDollar() (string, error) {
fallthrough
case '+', '-', '?', '#', '%':
rawEscapes := ch == '#' || ch == '%'
if nullIsUnset && rawEscapes {
return "", errors.Errorf("unsupported modifier (%s) in substitution", chs)
}
word, _, err := sw.processStopOn('}', rawEscapes)
if err != nil {
if sw.scanner.Peek() == scanner.EOF {
Expand Down
20 changes: 20 additions & 0 deletions frontend/dockerfile/shell/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,26 @@ func TestProcessWithMatches(t *testing.T) {
expected: "xxyy",
matches: map[string]struct{}{"FOO": {}, "BAR": {}},
},
{
input: "${FOO:#}",
envs: map[string]string{},
expectedErr: true,
},
{
input: "${FOO:##}",
envs: map[string]string{},
expectedErr: true,
},
{
input: "${FOO:%}",
envs: map[string]string{},
expectedErr: true,
},
{
input: "${FOO:%%}",
envs: map[string]string{},
expectedErr: true,
},
{
// test: wildcards
input: "${FOO/$NEEDLE/.} - ${FOO//$NEEDLE/.}",
Expand Down

0 comments on commit add7328

Please sign in to comment.