Skip to content

Commit

Permalink
NewBuilder(): always initialize Args
Browse files Browse the repository at this point in the history
We modify the Args map member of a Builder object, but we don't make a
copy of the initial value that we're given in NewBuilder() before doing
that, so we end up modifying the map that we're given.  This can be
surprising.

In the dispatcher for ARG instructions, we weren't checking that the map
wasn't nil before attempting to assign values to it, so we could panic.

Fix this by making a fresh map in NewBuilder() and initializing it using
the zero or more values from the passed-in map.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
  • Loading branch information
nalind committed May 27, 2020
1 parent ec55735 commit fcbf651
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ func NewBuilder(args map[string]string) *Builder {
for k, v := range builtinAllowedBuildArgs {
allowed[k] = v
}
provided := make(map[string]string)
for k, v := range args {
provided[k] = v
}
return &Builder{
Args: args,
Args: provided,
AllowedArgs: allowed,
}
}
Expand Down

0 comments on commit fcbf651

Please sign in to comment.