fix: handle nil values in field path and update tests#309
Conversation
Signed-off-by: Niklas Walter <walter.niklas@gmail.com>
|
Welcome @TwoStone! |
|
Hi @TwoStone. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Hi @liggitt and a happy new year - i hope you are the right to mention here - i just wanted to ask if you can give an estimation when the PR can get a first review. |
|
/approve Thanks! |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jpbetz, TwoStone The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@jpbetz this fix is needed to make it possible to use the fakeclient in controller runtime with an api that embedds a struct pointer. Is there any chance this could be backported into k8s 1.35? |
|
Any project can require this version of this dependency without needing k8s to bump, right? |
Oh you are right. Controller-Runtime actually has a direct dependency on it nowadays so we can bump that and thus pass the bump on to downstream projects. Thanks for the suggestion! |
Summary
Fixes a nil pointer dereference panic that occurs when
GetFromattempts to access fields from embedded structs that are nil pointers. This adds defensive nil checking when traversing field paths to safely return zero values instead of panicking.Problem
The
FieldCacheEntry.GetFrommethod invalue/reflectcache.gotraverses field paths usingFieldByIndexwithout checking if intermediate struct values are nil. When dealing with embedded pointer structs (e.g.,*testBasicStructembedded with,inlinetag), if the pointer is nil, callingFieldByIndexcauses a panic.Example scenario:
Impact