From 128c09f19df897ccc8e4aacebbc7d4ae5db16ae8 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 11 Oct 2017 22:24:29 +0200 Subject: syz-manager: expose raw cover in http handler This adds /rawcover handler which returns a file with all covered so far PCs, e.g.: 0xffffffff8100763e 0xffffffff81007667 ... 0xffffffff8100767d Useful for offline coverage processing, diffing coverage, etc. In particular allows to do: curl http://localhost:1234/rawcover | addr2line -e vmlinux --- syz-manager/html.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/syz-manager/html.go b/syz-manager/html.go index 2ceb4fc48..4c7c6de51 100644 --- a/syz-manager/html.go +++ b/syz-manager/html.go @@ -4,6 +4,7 @@ package main import ( + "bufio" "fmt" "html/template" "io" @@ -35,6 +36,7 @@ func (mgr *Manager) initHttp() { http.HandleFunc("/prio", mgr.httpPrio) http.HandleFunc("/file", mgr.httpFile) http.HandleFunc("/report", mgr.httpReport) + http.HandleFunc("/rawcover", mgr.httpRawCover) ln, err := net.Listen("tcp4", mgr.cfg.Http) if err != nil { @@ -289,6 +291,30 @@ func (mgr *Manager) httpReport(w http.ResponseWriter, r *http.Request) { } } +func (mgr *Manager) httpRawCover(w http.ResponseWriter, r *http.Request) { + mgr.mu.Lock() + defer mgr.mu.Unlock() + + base, err := getVmOffset(mgr.cfg.Vmlinux) + if err != nil { + http.Error(w, fmt.Sprintf("failed to get vmlinux base: %v", err), http.StatusInternalServerError) + return + } + + var cov cover.Cover + for _, inp := range mgr.corpus { + cov = cover.Union(cov, cover.Cover(inp.Cover)) + } + + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + buf := bufio.NewWriter(w) + for _, pc := range cov { + restored := cover.RestorePC(pc, base) - callLen + fmt.Fprintf(buf, "0x%x\n", restored) + } + buf.Flush() +} + func collectCrashes(workdir string) ([]*UICrashType, error) { crashdir := filepath.Join(workdir, "crashes") dirs, err := osutil.ListDir(crashdir) -- cgit mrf-deployment