forked from TrueCloudLab/neoneo-go
util: add error check to Read/WriteVarUint
Fixes possibility of bogus reads/writes. Suggested by @im-kulikov.
This commit is contained in:
parent
15311f202b
commit
7b46f9bb86
2 changed files with 8 additions and 0 deletions
|
@ -33,6 +33,10 @@ func (r *BinReader) ReadBE(v interface{}) {
|
|||
// ReadVarUint reads a variable-length-encoded integer from the
|
||||
// underlying reader
|
||||
func (r *BinReader) ReadVarUint() uint64 {
|
||||
if r.Err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
var b uint8
|
||||
r.Err = binary.Read(r.R, binary.LittleEndian, &b)
|
||||
|
||||
|
|
|
@ -32,6 +32,10 @@ func (w *BinWriter) WriteBE(v interface{}) {
|
|||
|
||||
// WriteVarUint writes a uint64 into the underlying writer using variable-length encoding
|
||||
func (w *BinWriter) WriteVarUint(val uint64) {
|
||||
if w.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if val < 0 {
|
||||
w.Err = errors.New("value out of range")
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue