Skip to content

Commit 3b088d9

Browse files
x/crypto/cryptobyte: reject negative Unwrite argument
Fixes golang/go#57112
1 parent 59ff472 commit 3b088d9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cryptobyte/builder.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ func (b *Builder) add(bytes ...byte) {
303303
b.result = append(b.result, bytes...)
304304
}
305305

306-
// Unwrite rolls back n bytes written directly to the Builder. An attempt by a
307-
// child builder passed to a continuation to unwrite bytes from its parent will
308-
// panic.
306+
// Unwrite rolls back non-negative n bytes written directly to the Builder.
307+
// An attempt by a child builder passed to a continuation to unwrite bytes
308+
// from its parent will panic.
309309
func (b *Builder) Unwrite(n int) {
310310
if b.err != nil {
311311
return
@@ -317,6 +317,9 @@ func (b *Builder) Unwrite(n int) {
317317
if length < 0 {
318318
panic("cryptobyte: internal error")
319319
}
320+
if n < 0 {
321+
panic("cryptobyte: attempted to unwrite negative number of bytes")
322+
}
320323
if n > length {
321324
panic("cryptobyte: attempted to unwrite more than was written")
322325
}

0 commit comments

Comments
 (0)