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

Fixing nil pointer deref on Scrapli send config errors #1723

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions nodes/vr_sros/vr-sros.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,16 @@ func (s *vrSROS) applyPartialConfig(ctx context.Context, addr, platformName, use
// converting byte slice to newline delimited string slice
cfgs := strings.Split(string(configContent), "\n")

mr, err := d.SendConfigs(cfgs)
if err != nil || mr.Failed != nil {
return fmt.Errorf("failed to apply config; error: %+v %+v", err, mr.Failed)
}
// condfig snippets should not have commit command, so we need to commit manually
r, err := d.SendConfig("commit")
if err != nil || r.Failed != nil {
return fmt.Errorf("failed to commit config; error: %+v %+v", err, mr.Failed)
}
cfgs = append(cfgs, "commit", "/admin save")

r, err = d.SendCommand("/admin save")
if err != nil || r.Failed != nil {
return fmt.Errorf("failed to persist config; error: %+v %+v", err, mr.Failed)
mr, err := d.SendConfigs(cfgs)
if err != nil || (mr != nil && mr.Failed != nil) {
if mr != nil {
return fmt.Errorf("failed to apply config; error: %+v %+v", err, mr.Failed)
Comment on lines +288 to +289
Copy link
Member

Choose a reason for hiding this comment

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

this one is not needed, as we check for mr != nil above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thats not correct.
its an OR up there ... we could do it in to seperate branches but ... same same

Copy link
Member

Choose a reason for hiding this comment

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

then here it shoudl also be if mr != nil && err != nil
otherwise the statement above might have err == nil, but mr.Failed != nil

} else {
return fmt.Errorf("failed to apply config; error: %+v", err)
}
}

return nil
Expand Down