Skip to content

Commit

Permalink
x/crypto/cryptobyte: reject negative Unwrite argument
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderYastrebov committed Feb 1, 2023
1 parent 59ff472 commit 3b088d9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cryptobyte/builder.go
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 3b088d9

Please sign in to comment.