diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-03-16 14:49:06 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-03-16 14:49:06 -0400 |
commit | 3bb022fb6f5c6d273e2787e10a28e821c88734d7 (patch) | |
tree | 052b3bda7febfd801206deb0db3cfeff23032731 | |
parent | 23d4356931c90d83913ca483cb0ec42bcc357f58 (diff) | |
download | getwtxt-3bb022fb6f5c6d273e2787e10a28e821c88734d7.tar.gz |
eliminated panic when serving requests from empty registry v0.4.11
when generating an etag from a query that returns no results, indexing into the byte slice caused that thread to panic. now checking for a nil byte slice or a small byte slice in handlers.go:46:getEtag() on nil byte slice, return empty string for etag. on small byte slice, don't truncate it, but return the whole thing.
-rw-r--r-- | svc/handlers.go | 6 | ||||
-rw-r--r-- | svc/query.go | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/svc/handlers.go b/svc/handlers.go index ee58622..7ce4b77 100644 --- a/svc/handlers.go +++ b/svc/handlers.go @@ -45,6 +45,12 @@ func getEtagFromTime(modtime time.Time) string { // responses. func getEtag(data []byte) string { bytes := fnv.New32().Sum(data) + if bytes == nil { + return "" + } + if len(bytes) < 16 { + return fmt.Sprintf("%x", bytes) + } return fmt.Sprintf("%x", bytes[:16]) } diff --git a/svc/query.go b/svc/query.go index 7047df3..8f22838 100644 --- a/svc/query.go +++ b/svc/query.go @@ -61,7 +61,7 @@ func dedupe(list []string) []string { // appending each entry to a byte slice, and adding // newlines where appropriate. func parseQueryOut(out []string) []byte { - var data []byte + data := make([]byte, 0) for i, e := range out { data = append(data, []byte(e)...) |