Skip to content

Commit abcc835

Browse files
Copilotbootjp
andcommitted
Fix nil pointer dereference in GRPC server methods
Co-authored-by: bootjp <[email protected]>
1 parent 4d37347 commit abcc835

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

adapter/grpc.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ func (r GRPCServer) RawPut(_ context.Context, req *pb.RawPutRequest) (*pb.RawPut
6767

6868
res, err := r.coordinator.Dispatch(m)
6969
if err != nil {
70+
commitIndex := uint64(0)
71+
if res != nil {
72+
commitIndex = res.CommitIndex
73+
}
7074
return &pb.RawPutResponse{
71-
CommitIndex: res.CommitIndex,
75+
CommitIndex: commitIndex,
7276
Success: false,
7377
}, errors.WithStack(err)
7478
}
@@ -87,8 +91,12 @@ func (r GRPCServer) RawDelete(ctx context.Context, req *pb.RawDeleteRequest) (*p
8791

8892
res, err := r.coordinator.Dispatch(m)
8993
if err != nil {
94+
commitIndex := uint64(0)
95+
if res != nil {
96+
commitIndex = res.CommitIndex
97+
}
9098
return &pb.RawDeleteResponse{
91-
CommitIndex: res.CommitIndex,
99+
CommitIndex: commitIndex,
92100
Success: false,
93101
}, errors.WithStack(err)
94102
}
@@ -121,8 +129,12 @@ func (r GRPCServer) Put(ctx context.Context, req *pb.PutRequest) (*pb.PutRespons
121129

122130
res, err := r.coordinator.Dispatch(reqs)
123131
if err != nil {
132+
commitIndex := uint64(0)
133+
if res != nil {
134+
commitIndex = res.CommitIndex
135+
}
124136
return &pb.PutResponse{
125-
CommitIndex: res.CommitIndex,
137+
CommitIndex: commitIndex,
126138
}, errors.WithStack(err)
127139
}
128140

@@ -162,8 +174,12 @@ func (r GRPCServer) Delete(ctx context.Context, req *pb.DeleteRequest) (*pb.Dele
162174

163175
res, err := r.coordinator.Dispatch(reqs)
164176
if err != nil {
177+
commitIndex := uint64(0)
178+
if res != nil {
179+
commitIndex = res.CommitIndex
180+
}
165181
return &pb.DeleteResponse{
166-
CommitIndex: res.CommitIndex,
182+
CommitIndex: commitIndex,
167183
}, errors.WithStack(err)
168184
}
169185

0 commit comments

Comments
 (0)