Skip to content

Bug Report: Potential Nil Pointer Dereference in KvGetSecret #25

Description

@kuba-vodafone

Description

During writing tests when I tried to read not existed secret, I have encountered a potential nil pointer dereference issue in the KvGetSecret function of this project. This issue arises when attempting to access the kvsecret.Data field without proper checks for nil values. The existing code may result in a runtime error.

Steps to Reproduce

  1. Execute the following code:
    kvsecret, err := KvGetSecret(client, kvOptions.vault_kv_engine, kvOptions.vault_kv_version, path)
    if err != nil || kvsecret == nil || kvsecret.Data == nil {
        errMsg := fmt.Sprintf("failed to read the secrets in folder %s: %s", path, err)
        hclog.L().Error(errMsg)
        return nil, fmt.Errorf(errMsg)
    }

Expected Behavior

The code should handle potential nil values appropriately, preventing nil pointer dereference.

Actual Behavior

The current implementation may lead to a runtime error when trying to access kvsecret.Data and it does

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1826f9e]

Environment

  • Project Version/Commit: feature/kv-ops
  • Go Version: go1.21.3
  • Operating System: darwin/macos

Additional Information

I recommend modifying the code to include a thorough nil check for kvsecret and kvsecret.Data to avoid potential nil pointer dereference issues.

Possible solutions

#24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions