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
- 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
Description
During writing tests when I tried to read not existed secret, I have encountered a potential nil pointer dereference issue in the
KvGetSecretfunction of this project. This issue arises when attempting to access thekvsecret.Datafield without proper checks for nil values. The existing code may result in a runtime error.Steps to Reproduce
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.Dataand it doesEnvironment
Additional Information
I recommend modifying the code to include a thorough nil check for
kvsecretandkvsecret.Datato avoid potential nil pointer dereference issues.Possible solutions
#24