Skip to content

Commit

Permalink
cryptobyte: reject negative Unwrite argument
Browse files Browse the repository at this point in the history
Fixes golang/go#57112

Change-Id: I7a533046a6451d7ae3704eb81e6ddeec8442cf06
GitHub-Last-Rev: 3b088d9
GitHub-Pull-Request: golang#249
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/464338
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
  • Loading branch information
AlexanderYastrebov authored and maisem committed Jul 11, 2023
1 parent 75d48e6 commit 520eed3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cryptobyte/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ func (b *Builder) add(bytes ...byte) {
b.result = append(b.result, bytes...)
}

// Unwrite rolls back n bytes written directly to the Builder. An attempt by a
// child builder passed to a continuation to unwrite bytes from its parent will
// panic.
// Unwrite rolls back non-negative n bytes written directly to the Builder.
// An attempt by a child builder passed to a continuation to unwrite bytes
// from its parent will panic.
func (b *Builder) Unwrite(n int) {
if b.err != nil {
return
Expand All @@ -317,6 +317,9 @@ func (b *Builder) Unwrite(n int) {
if length < 0 {
panic("cryptobyte: internal error")
}
if n < 0 {
panic("cryptobyte: attempted to unwrite negative number of bytes")
}
if n > length {
panic("cryptobyte: attempted to unwrite more than was written")
}
Expand Down

0 comments on commit 520eed3

Please sign in to comment.