Skip to content

Commit 9717dbb

Browse files
rohrerjjuagargi
authored andcommitted
daemon: error out when using drkey endpoints without configured drkey (scionproto#4453)
I found a bug in the SCION daemon. If you create a SCION daemon connection and call one of the drkey endpoints without first setting the configuration value "drkey_level2_db.Connection" to something meaningful, the SCION daemon will encounter an error like that and crash: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xb82d33] ``` This bug can easily be reproduced by running a code snippet like this for a SCION daemon that has no drkey configured: ``` sd, _ := daemon.NewService(daemonAddr).Connect(ctx) sd.DRKeyGetASHostKey(ctx, drkey.ASHostMeta{}) ``` The problem is that in the file "daemon/internal/servers/grpc.go", when the drkey endpoints are called, DaemonServer.DRKeyClient is nil if it is not configured as described above. Fixed by explicitly checking whether DRKey is available and erroring out if it is not.
1 parent b14695f commit 9717dbb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

daemon/internal/servers/grpc.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ func (s *DaemonServer) DRKeyASHost(
356356
req *pb_daemon.DRKeyASHostRequest,
357357
) (*pb_daemon.DRKeyASHostResponse, error) {
358358

359+
if s.DRKeyClient == nil {
360+
return nil, serrors.New("DRKey is not available")
361+
}
359362
meta, err := requestToASHostMeta(req)
360363
if err != nil {
361364
return nil, serrors.WrapStr("parsing protobuf ASHostReq", err)
@@ -378,6 +381,9 @@ func (s *DaemonServer) DRKeyHostAS(
378381
req *pb_daemon.DRKeyHostASRequest,
379382
) (*pb_daemon.DRKeyHostASResponse, error) {
380383

384+
if s.DRKeyClient == nil {
385+
return nil, serrors.New("DRKey is not available")
386+
}
381387
meta, err := requestToHostASMeta(req)
382388
if err != nil {
383389
return nil, serrors.WrapStr("parsing protobuf HostASReq", err)
@@ -400,6 +406,9 @@ func (s *DaemonServer) DRKeyHostHost(
400406
req *pb_daemon.DRKeyHostHostRequest,
401407
) (*pb_daemon.DRKeyHostHostResponse, error) {
402408

409+
if s.DRKeyClient == nil {
410+
return nil, serrors.New("DRKey is not available")
411+
}
403412
meta, err := requestToHostHostMeta(req)
404413
if err != nil {
405414
return nil, serrors.WrapStr("parsing protobuf HostHostReq", err)

0 commit comments

Comments
 (0)