server: abort request handling on bad requests
A request to a hostname that hasn't been registered with the server currently results in a nil pointer deref panic in server.go:215 as request handling continues even if ReadRequest() returns an error. This change changes all if-else error handling in Server.respond() to a WriteStatus-call and early return. This makes it clear when request handling is aborted (and actually aborts when ReadRequest() fails).
This commit is contained in:
parent
c8626bae17
commit
efef44c2f9
12
server.go
12
server.go
@ -188,7 +188,9 @@ func (s *Server) respond(conn net.Conn) {
|
||||
req, err := ReadRequest(conn)
|
||||
if err != nil {
|
||||
w.WriteStatus(StatusBadRequest)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
// Store information about the TLS connection
|
||||
if tlsConn, ok := conn.(*tls.Conn); ok {
|
||||
req.TLS = tlsConn.ConnectionState()
|
||||
@ -201,14 +203,14 @@ func (s *Server) respond(conn net.Conn) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resp := s.responder(req)
|
||||
if resp != nil {
|
||||
resp.Respond(w, req)
|
||||
} else {
|
||||
if resp == nil {
|
||||
w.WriteStatus(StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
resp.Respond(w, req)
|
||||
}
|
||||
|
||||
func (s *Server) responder(r *Request) Responder {
|
||||
|
Loading…
Reference in New Issue
Block a user