From c848e7971ae7137ae3abd9601ccf250f1f2ee58d Mon Sep 17 00:00:00 2001 From: Oren Shomron Date: Mon, 5 Nov 2018 14:50:38 -0500 Subject: [PATCH] Fix scan for body parameter in ksonnet.parsePaths() 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 --- ksonnet-gen/ksonnet/paths.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ksonnet-gen/ksonnet/paths.go b/ksonnet-gen/ksonnet/paths.go index 55200d1..5e48576 100644 --- a/ksonnet-gen/ksonnet/paths.go +++ b/ksonnet-gen/ksonnet/paths.go @@ -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 = ¶m + 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)