Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
[APP-5742] Fix nil pointer bugs (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Otterverse authored Jul 30, 2024
1 parent aceac0b commit e6aabca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 11 additions & 4 deletions networkmanager/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (w *NMWrapper) GetSmartMachineStatus(ctx context.Context,
defer w.dataMu.Unlock()

w.state.setLastInteraction()
lastNetwork := w.networks[w.lastSSID].getInfo()

ret := &pb.GetSmartMachineStatusResponse{
ProvisioningInfo: &pb.ProvisioningInfo{
Expand All @@ -51,10 +50,15 @@ func (w *NMWrapper) GetSmartMachineStatus(ctx context.Context,
},
HasSmartMachineCredentials: w.state.getConfigured(),
IsOnline: w.state.getOnline(),
LatestConnectionAttempt: provisioning.NetworkInfoToProto(&lastNetwork),
Errors: w.errListAsStrings(),
}

lastNetwork, ok := w.networks[w.lastSSID]
if ok {
lastNetworkInfo := lastNetwork.getInfo()
ret.LatestConnectionAttempt = provisioning.NetworkInfoToProto(&lastNetworkInfo)
}

// reset the errors, as they were now just displayed
w.errors = nil

Expand All @@ -78,8 +82,11 @@ func (w *NMWrapper) SetNetworkCredentials(ctx context.Context,
w.input.PSK = req.GetPsk()
w.inputReceived.Store(true)

if req.GetSsid() == w.lastSSID {
w.networks[w.lastSSID].lastError = nil
if req.GetSsid() == w.lastSSID && w.lastSSID != "" {
lastNetwork, ok := w.networks[w.lastSSID]
if ok {
lastNetwork.lastError = nil
}
}

return &pb.SetNetworkCredentialsResponse{}, nil
Expand Down
7 changes: 5 additions & 2 deletions networkmanager/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ func (w *NMWrapper) portalSave(resp http.ResponseWriter, req *http.Request) {
w.banner += "Added credentials for SSID: " + w.input.SSID
}

if ssid == w.lastSSID && w.networks[w.lastSSID] != nil {
w.networks[w.lastSSID].lastError = nil
if ssid == w.lastSSID && ssid != "" {
lastNetwork, ok := w.networks[w.lastSSID]
if ok {
lastNetwork.lastError = nil
}
}
w.input.Updated = time.Now()
w.inputReceived.Store(true)
Expand Down

0 comments on commit e6aabca

Please sign in to comment.