Skip to content

Commit

Permalink
issue: fix nil pointer dereference on plumb error
Browse files Browse the repository at this point in the history
plumbserve() fails with a nil pointer dereference when it tries to
print errors via w.Err(). This happens because w is a dummy window
with a nil *acme.Win. This commit  replaces w.Err() calls in
plumbserve() with log.Printf(). It also extracts the plumbserve()
method out of *awin, given that the previous change removes this
dependency.

Fixes issue rsc#5.
  • Loading branch information
jroimartin committed Jan 11, 2020
1 parent 7a65b24 commit 8fa163d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions issue/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ func acmeMode() {
dummy.Look("all")
}

go dummy.plumbserve()
go plumbserve()

select {}
}

func (w *awin) plumbserve() {
func plumbserve() {
fid, err := plumb.Open("githubissue", 0)
if err != nil {
w.Err(fmt.Sprintf("plumb: %v", err))
log.Printf("plumb: %v", err)
return
}
r := bufio.NewReader(fid)
for {
var m plumb.Message
if err := m.Recv(r); err != nil {
w.Err(fmt.Sprintf("plumb recv: %v", err))
log.Printf("plumb recv: %v", err)
return
}
if m.Type != "text" {
w.Err(fmt.Sprintf("plumb recv: unexpected type: %s\n", m.Type))
log.Printf("plumb recv: unexpected type: %s", m.Type)
continue
}
if m.Dst != "githubissue" {
w.Err(fmt.Sprintf("plumb recv: unexpected dst: %s\n", m.Dst))
log.Printf("plumb recv: unexpected dst: %s", m.Dst)
continue
}
// TODO use m.Dir
Expand All @@ -92,26 +92,26 @@ func (w *awin) plumbserve() {
project = data[len("/issue/"):]
i := strings.LastIndex(project, "/")
if i < 0 {
w.Err(fmt.Sprintf("plumb recv: bad text %q", data))
log.Printf("plumb recv: bad text %q", data)
continue
}
project, what = project[:i], project[i+1:]
} else {
i := strings.Index(data, "#")
if i < 0 {
w.Err(fmt.Sprintf("plumb recv: bad text %q", data))
log.Printf("plumb recv: bad text %q", data)
continue
}
project, what = data[:i], data[i+1:]
}
if strings.Count(project, "/") != 1 {
w.Err(fmt.Sprintf("plumb recv: bad text %q", data))
log.Printf("plumb recv: bad text %q", data)
continue
}
var plummy awin
plummy.prefix = "/issue/" + project + "/"
if !plummy.Look(what) {
w.Err(fmt.Sprintf("plumb recv: can't look %s%s", plummy.prefix, what))
log.Printf("plumb recv: can't look %s%s", plummy.prefix, what)
}
}
}
Expand Down

0 comments on commit 8fa163d

Please sign in to comment.