From: Samuel Tan Date: Tue, 11 Jun 2019 05:18:56 +0000 (-0700) Subject: html/template: handle nil Error values in context.String X-Git-Tag: go1.13beta1~65 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=db042d2d42e1009bb9d6c12a7a018108638e1dae;p=gostls13.git html/template: handle nil Error values in context.String Add a special case to print a generic nil error when context.err is nil. Previously, this case was unchecked, leading to a call to (*Error).Error with a nil receiver, which was triggering a nil pointer access. However, this bug was masked by the panic-recovery code in package fmt. I tested this change by running `dlv test` in src/html/template, running the `continue` command, and verifying that no "bad access" errors are returned. Fixes #28854 Change-Id: I0b637b943de003d9efc294f6f1e49b793668d037 Reviewed-on: https://go-review.googlesource.com/c/go/+/181579 Reviewed-by: Dmitri Shuralyov --- diff --git a/src/html/template/context.go b/src/html/template/context.go index 7ab3d1fed6..f7d4849928 100644 --- a/src/html/template/context.go +++ b/src/html/template/context.go @@ -26,7 +26,11 @@ type context struct { } func (c context) String() string { - return fmt.Sprintf("{%v %v %v %v %v %v %v}", c.state, c.delim, c.urlPart, c.jsCtx, c.attr, c.element, c.err) + var err error + if c.err != nil { + err = c.err + } + return fmt.Sprintf("{%v %v %v %v %v %v %v}", c.state, c.delim, c.urlPart, c.jsCtx, c.attr, c.element, err) } // eq reports whether two contexts are equal.