浏览代码

More review feedback

Guillaume Ballet 6 年之前
父节点
当前提交
6f21520a82
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      accounts/scwallet/apdu.go

+ 5 - 0
accounts/scwallet/apdu.go

@@ -19,6 +19,7 @@ package scwallet
 import (
 	"bytes"
 	"encoding/binary"
+	"fmt"
 )
 
 // commandAPDU represents an application data unit sent to a smartcard.
@@ -66,6 +67,10 @@ type responseAPDU struct {
 
 // deserialize deserializes a response APDU.
 func (ra *responseAPDU) deserialize(data []byte) error {
+	if len(data) < 2 {
+		return fmt.Errorf("can not deserialize data: payload too short (%d < 2)", len(data))
+	}
+
 	ra.Data = make([]byte, len(data)-2)
 
 	buf := bytes.NewReader(data)