Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash related to empty block in lb_vs resource #1463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

annakhm
Copy link
Collaborator

@annakhm annakhm commented Nov 6, 2024

Empty block can be configured when no required attributes are defined in the block. In this case nil protection is required, since empty block is presented as nil rather than empty map in the schema structure.

Empty block can be configured when no required attributes are
defined in the block. In this case nil protection is required,
since empty block is presented as nil rather than empty map in the
schema structure.

Signed-off-by: Anna Khmelnitsky <[email protected]>
@@ -903,6 +903,10 @@ func getPolicyLbRuleVariablePersistenceLearnActionSchema() *schema.Schema {
func getPolicyClientSSLBindingFromSchema(d *schema.ResourceData) *model.LBClientSslProfileBinding {
bindings := d.Get("client_ssl").([]interface{})
for _, binding := range bindings {
if binding == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unsafe as d.Get() result can be nil as well and casting it will result a crash.
As we have multiple instances in the scope of this resource and multiple others in other resources, can we use a func instead of the range which will do all the validations, e.g check that input (d.Get() result) is not null, that members aren't null as well etc?
e.g:

func iterateSchemaSlice(s interface{}, f func(interface{})) {
    if s == nil {
        return
    }
    for _, i := range s.([]interface{}) {
        if i == nil {
            continue
        }
        f(i)
    }
}

And call it as:

  iterateSchemaSlice(d.Get("client_ssl"), func(binding interface{}){
		data := binding.(map[string]interface{})
		chainDepth := int64(data["certificate_chain_depth"].(int))    
  })

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the key exists in schema, then nil is not expected to be returned, as stated here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

While creating nsxt_policy_lb_virtual_server along with dynamic rule set, getting error.
2 participants