Controller crashes with null pointer exception when given incomplete topology creation request
When you post an incomplete topology creation request with missing fields in the port config, instead of giving an error message, the controller crashes with an null pointer exception.
Description
Expected Behavior
Return a http error.
Actual Behavior
Null pointer exception.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x191b945]
goroutine 378 [running]:
code.fbi.h-da.de/danet/gosdn/controller/northbound/server.(*TopologyServer).ensureNodeAndPortExists(0xc003936c60, 0xc0037d02d0, 0xc0037d0370)
/home/neil/code/gosdn/controller/northbound/server/topology.go:161 +0x205
code.fbi.h-da.de/danet/gosdn/controller/northbound/server.(*TopologyServer).AddLink(0xc003936c60, {0xc0037a5440?, 0xd98f86?}, 0xc0037a5440)
/home/neil/code/gosdn/controller/northbound/server/topology.go:42 +0x85
code.fbi.h-da.de/danet/gosdn/api/go/gosdn/topology._TopologyService_AddLink_Handler({0x1c1c160?, 0xc003936c60}, {0x2119068, 0xc00374f470}, 0xc0001f33b0, 0x0)
/home/neil/code/gosdn/api/go/gosdn/topology/topology_grpc.pb.go:117 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc003968000, {0x211f858, 0xc003a15a00}, 0xc0036ebe60, 0xc0039370e0, 0x2c5a880, 0x0)
/home/neil/go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:1295 +0xb2b
google.golang.org/grpc.(*Server).handleStream(0xc003968000, {0x211f858, 0xc003a15a00}, 0xc0036ebe60, 0x0)
/home/neil/go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:1636 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
/home/neil/go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
/home/neil/go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:930 +0x28a
make: *** [Makefile:37: start-insecure] Error 2
Possible Fix
Steps to Reproduce
Post the following request to /topology/create
{
"timestamp": "1649929667405420000",
"link": {
"name": "test",
"sourceNode": {
"name": "ceos0",
"id": "5adee9ec-c865-4964-bb1b-faa4d4449d73"
},
"targetNode": {
"name": "ceos1a",
"id": "1fadc5fd-4c0c-404f-be61-b2b0193fba61"
},
"sourcePort": {
"name": "eth1"
},
"targetPort": {
"name": "eth1"
}
}
}
Context
Your Environment
- Version used:
- Environment name and version (e.g. go v1.16.3 on FreeBSD 13.0-current):
- Server type and version:
- Operating System and version: