diff options
author | 2024-06-17 08:12:25 +0000 | |
---|---|---|
committer | 2024-06-17 08:12:25 +0000 | |
commit | 3a01377bcc30105d11f5971b775c561d9ca71253 (patch) | |
tree | b1862ce5771ac823c105a6a9543098814abd5dcb /vendor/github.com/miekg/dns/scan_rr.go | |
parent | [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.33 to 2.20.34 (#3017) (diff) | |
download | gotosocial-3a01377bcc30105d11f5971b775c561d9ca71253.tar.xz |
[chore]: Bump github.com/miekg/dns from 1.1.59 to 1.1.61 (#3014)
Diffstat (limited to 'vendor/github.com/miekg/dns/scan_rr.go')
-rw-r--r-- | vendor/github.com/miekg/dns/scan_rr.go | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/vendor/github.com/miekg/dns/scan_rr.go b/vendor/github.com/miekg/dns/scan_rr.go index 7d1ade7d8..c1a76995e 100644 --- a/vendor/github.com/miekg/dns/scan_rr.go +++ b/vendor/github.com/miekg/dns/scan_rr.go @@ -55,7 +55,10 @@ func endingToTxtSlice(c *zlexer, errstr string) ([]string, *ParseError) { sx := []string{} p := 0 for { - i := escapedStringOffset(l.token[p:], 255) + i, ok := escapedStringOffset(l.token[p:], 255) + if !ok { + return nil, &ParseError{err: errstr, lex: l} + } if i != -1 && p+i != len(l.token) { sx = append(sx, l.token[p:p+i]) } else { @@ -1919,29 +1922,36 @@ func (rr *APL) parse(c *zlexer, o string) *ParseError { // escapedStringOffset finds the offset within a string (which may contain escape // sequences) that corresponds to a certain byte offset. If the input offset is -// out of bounds, -1 is returned. -func escapedStringOffset(s string, byteOffset int) int { - if byteOffset == 0 { - return 0 +// out of bounds, -1 is returned (which is *not* considered an error). +func escapedStringOffset(s string, desiredByteOffset int) (int, bool) { + if desiredByteOffset == 0 { + return 0, true } - offset := 0 - for i := 0; i < len(s); i++ { - offset += 1 + currentByteOffset, i := 0, 0 + + for i < len(s) { + currentByteOffset += 1 // Skip escape sequences if s[i] != '\\' { - // Not an escape sequence; nothing to do. + // Single plain byte, not an escape sequence. + i++ } else if isDDD(s[i+1:]) { - i += 3 + // Skip backslash and DDD. + i += 4 + } else if len(s[i+1:]) < 1 { + // No character following the backslash; that's an error. + return 0, false } else { - i++ + // Skip backslash and following byte. + i += 2 } - if offset >= byteOffset { - return i + 1 + if currentByteOffset >= desiredByteOffset { + return i, true } } - return -1 + return -1, true } |