From a762c94d61c6bf3e1beecc6334a50c2a76520d5b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 20 Feb 2017 17:43:59 -0800 Subject: [PATCH] Only try to parse the MAC address if the file has a known type. Parsing unconditionally logs errors when serving non-kernel/initrd files. --- pixiecore/http.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pixiecore/http.go b/pixiecore/http.go index db17449..3dbb0cb 100644 --- a/pixiecore/http.go +++ b/pixiecore/http.go @@ -134,15 +134,20 @@ func (s *Server) handleFile(w http.ResponseWriter, r *http.Request) { } s.log("HTTP", "Sent file %q to %s", name, r.RemoteAddr) - mac, err := net.ParseMAC(r.URL.Query().Get("mac")) - if err != nil { - s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac")) - return - } switch r.URL.Query().Get("type") { case "kernel": + mac, err := net.ParseMAC(r.URL.Query().Get("mac")) + if err != nil { + s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac")) + return + } s.machineEvent(mac, machineStateKernel, "Sent kernel %q", name) case "initrd": + mac, err := net.ParseMAC(r.URL.Query().Get("mac")) + if err != nil { + s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac")) + return + } s.machineEvent(mac, machineStateInitrd, "Sent initrd %q", name) } }