aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorRebecca Stambler <rstambler@golang.org>2018-06-04 15:12:45 -0400
committerHeschi Kreinick <heschi@google.com>2018-06-04 22:06:42 +0000
commitb219a68ad957462470695bcd0333e24ea9bdf08c (patch)
tree5df5664f53a7ae9b47ddbf6a10e198280e486980 /src/strconv
parentd0228b03bd77e048504877797e53e3f16b149d8f (diff)
downloadgo-b219a68ad957462470695bcd0333e24ea9bdf08c.tar.gz
go-b219a68ad957462470695bcd0333e24ea9bdf08c.zip
strconv: check for empty string in UnquoteChar
The existing implementation panics on malformed input of an empty string. strconv.Unquote validates the length of the inputs, but calling UnquoteChar directly with an empty string leads to a panic, so add a check for length. Also, add a test to go/constant to ensure that MakeFromLiteral does not panic on malformed input such as "const x = ''". Change-Id: I4217e38db48a09a21ec414bbfb3087709da62904 Reviewed-on: https://go-review.googlesource.com/116215 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/quote.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/strconv/quote.go b/src/strconv/quote.go
index d514b5f552..9b7194a0f0 100644
--- a/src/strconv/quote.go
+++ b/src/strconv/quote.go
@@ -237,6 +237,10 @@ func unhex(b byte) (v rune, ok bool) {
// If set to zero, it does not permit either escape and allows both quote characters to appear unescaped.
func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error) {
// easy cases
+ if len(s) == 0 {
+ err = ErrSyntax
+ return
+ }
switch c := s[0]; {
case c == quote && (quote == '\'' || quote == '"'):
err = ErrSyntax