cybozu-go / aptutil

Go utilities for Debian APT repositories
MIT License
124 stars 29 forks source link

go-apt-cacher panics with base prefix #30

Closed jacksgt closed 6 years ago

jacksgt commented 6 years ago

Hi,

I just found an interesting failure in go-apt-cacher (I'm running the latest master/HEAD version).

Using the default config file (which maps ubuntu to http://archive.ubuntu.com/ubuntu), the server panics when querying http://go-apt-cacher:3142/ubuntu/

$ go-apt-cacher --loglevel debug
2017-12-19T13:19:32.594886Z 1eec099b553c go-apt-cacher debug: "request path" path="ubuntu"
panic: path must has a prefix: ubuntu

goroutine 33 [running]:
github.com/cybozu-go/aptutil/cacher.(*Cacher).download(0xc42017a240, 0x89dcc0, 0xc420420120, 0xc42043c005, 0x6, 0xc42018e200, 0x0)
    /go/src/github.com/cybozu-go/aptutil/cacher/cacher.go:338 +0x142a
github.com/cybozu-go/aptutil/cacher.(*Cacher).Download.func1(0x89dc40, 0xc420400100, 0x89dc40, 0xc420400100)
    /go/src/github.com/cybozu-go/aptutil/cacher/cacher.go:256 +0x62
github.com/cybozu-go/cmd.(*Environment).Go.func1(0xc4200982a0, 0xc42041a060)
    /go/src/github.com/cybozu-go/cmd/env.go:133 +0x86
created by github.com/cybozu-go/cmd.(*Environment).Go
    /go/src/github.com/cybozu-go/cmd/env.go:130 +0xaf

caused by a simple:

curl -i 172.17.0.2:3142/ubuntu/

The panic is caused by the following statement in cacher/cacher.go:L338

t := strings.SplitN(path.Clean(p), "/", 2)
if len(t) != 2 {
    panic("path must has a prefix: " + p)
}

I don't think its adequate behavior to kill the server just because of this. go-apt-cacher should either serve the index.html of http://archive.ubuntu.com/ubuntu/ or just reply with 404.

ymmt2005 commented 6 years ago

Thanks again. Will take a look.

ymmt2005 commented 6 years ago

Verified as reported.

jacksgt commented 6 years ago

Thanks for the super quick fix!