From 5bfe94bb6ef2a2b25697aa6d08640e0ceae86e3d Mon Sep 17 00:00:00 2001 From: Catena cyber <35799796+catenacyber@users.noreply.github.com> Date: Tue, 28 Apr 2020 09:21:06 +0200 Subject: [PATCH] Efficient string concatenation (#1105) Found by oss-fuzz --- scan_rr.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scan_rr.go b/scan_rr.go index 3fe8a82a..11b08ad1 100644 --- a/scan_rr.go +++ b/scan_rr.go @@ -1,6 +1,7 @@ package dns import ( + "bytes" "encoding/base64" "net" "strconv" @@ -10,15 +11,15 @@ import ( // A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces) // or an error func endingToString(c *zlexer, errstr string) (string, *ParseError) { - var s string + var buffer bytes.Buffer l, _ := c.Next() // zString for l.value != zNewline && l.value != zEOF { if l.err { - return s, &ParseError{"", errstr, l} + return buffer.String(), &ParseError{"", errstr, l} } switch l.value { case zString: - s += l.token + buffer.WriteString(l.token) case zBlank: // Ok default: return "", &ParseError{"", errstr, l} @@ -26,7 +27,7 @@ func endingToString(c *zlexer, errstr string) (string, *ParseError) { l, _ = c.Next() } - return s, nil + return buffer.String(), nil } // A remainder of the rdata with embedded spaces, split on unquoted whitespace