Skip to content

Commit cef90e8

Browse files
committed
Fix nil pointer access in getBpfAppState functions
This commit fixes a nil pointer dereference in getBpfAppState. The getBpfAppState() functions now logs the state name from the found object (appProgramList.Items[0].Name) instead of trying to access the uninitialised r.currentAppState.Name field. These fixes prevent panics that occurred when getBpfAppState was called before currentAppState was initialised in the reconciliation flow. Signed-off-by: Andrew McDermott <[email protected]>
1 parent c893e23 commit cef90e8

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

controllers/bpfman-agent/cl_application_program.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,7 @@ func (r *ClBpfApplicationReconciler) getBpfAppState(ctx context.Context) (*bpfma
547547

548548
switch len(appProgramList.Items) {
549549
case 1:
550-
// We got exactly one BpfApplicationState, so update r.currentAppState
551-
r.Logger.V(1).Info("Found BpfApplicationState", "Name", r.currentAppState.Name)
550+
r.Logger.V(1).Info("Found BpfApplicationState", "Name", appProgramList.Items[0].Name)
552551
return &appProgramList.Items[0], nil
553552
case 0:
554553
// No BpfApplicationState found, so return nil

controllers/bpfman-agent/ns_application_program.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ func (r *NsBpfApplicationReconciler) getBpfAppState(ctx context.Context) (*bpfma
490490

491491
switch len(appProgramList.Items) {
492492
case 1:
493-
// We got exactly one BpfApplicationState, so update r.currentAppState
494-
r.Logger.V(1).Info("Found BpfApplicationState", "Name", r.currentAppState.Name)
493+
r.Logger.V(1).Info("Found BpfApplicationState", "Name", appProgramList.Items[0].Name)
495494
return &appProgramList.Items[0], nil
496495
case 0:
497496
// No BpfApplicationState found, so return nil

0 commit comments

Comments
 (0)