fix(uds): guard against nil VolumeServer in handleLocate

Prevent nil pointer dereference when VolumeServer is nil by adding
an early return with UdsStatusError before accessing vs.store.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
pingqiu
2026-02-08 10:58:36 -08:00
co-authored by Claude Opus 4.6
parent e064c86d12
commit f20c05ea0a
2 changed files with 8 additions and 4 deletions
+5
View File
@@ -189,6 +189,11 @@ func (u *UdsServer) handleLocate(req *LocateRequest) *LocateResponse {
return resp
}
if u.vs == nil {
resp.Status = UdsStatusError
return resp
}
volumeId := fileId.VolumeId
needleId := fileId.Key
+3 -4
View File
@@ -162,11 +162,10 @@ func TestUdsServerProtocol(t *testing.T) {
t.Fatalf("Failed to read response: %v", err)
}
// Since vs is nil, we expect an error status (handleLocate will panic or return error)
// In this case, we just check we got a valid response back
// Since vs is nil, we expect UdsStatusError
status := respBuf[0]
if status != UdsStatusOk && status != UdsStatusNotFound && status != UdsStatusError {
t.Errorf("Unexpected status: %d", status)
if status != UdsStatusError {
t.Errorf("Expected UdsStatusError (%d) for nil VolumeServer, got %d", UdsStatusError, status)
}
}