Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Fix scan for body parameter in ksonnet.parsePaths()
Browse files Browse the repository at this point in the history
Previously, body was assigned the address of the iteration variable.
Since this variable is reused, additional parameters following the body would
overwrite it and be used in its stead, leading to undefined behavior
(such as the panic described in the linked issue).

Addresses ksonnet/ksonnet#883

Signed-off-by: Oren Shomron <shomron@gmail.com>
  • Loading branch information
shomron committed Nov 5, 2018
1 parent ed0796f commit c848e79
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ksonnet-gen/ksonnet/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ func parsePaths(apiSpec *spec.Swagger) (map[string]Component, error) {
continue
}

var body *spec.Parameter
var body spec.Parameter
var hasBody bool
for _, param := range verb.Parameters {
if param.Name == "body" {
body = &param
body = param // shallow copy
hasBody = true
break
}
}

if body == nil {
if !hasBody {
continue
}

if body.Schema == nil {
return nil, errors.Errorf("invalid body parameter - missing required field: schema")
}
ref := extractRef(*body.Schema)

component, exists, err := pathExtensionComponent(verb.Extensions)
Expand Down

0 comments on commit c848e79

Please sign in to comment.