Skip to content

Commit 310bfa4

Browse files
AlexanderYastrebovgopherbot
authored andcommitted
cryptobyte: reject negative Unwrite argument
Fixes golang/go#57112 Change-Id: I7a533046a6451d7ae3704eb81e6ddeec8442cf06 GitHub-Last-Rev: 3b088d9 GitHub-Pull-Request: #249 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/464338 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 59ff472 commit 310bfa4

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)