diff --git a/cmd/root.go b/cmd/root.go index c2a7f3c3b921170d653483ef3a00d2ed825ee04d..886756c4709f8e771b08272e6e11e0c82414557b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -251,13 +251,13 @@ func readContact() contact.Contact { return contact.Contact{} } data, err := ioutil.ReadFile(inputFilePath) - jww.INFO.Printf("Size read in: %d", len(data)) + jww.INFO.Printf("Contact file size read in: %d", len(data)) if err != nil { - jww.FATAL.Panicf("%+v", err) + jww.FATAL.Panicf("Failed to read contact file: %+v", err) } c, err := contact.Unmarshal(data) if err != nil { - jww.FATAL.Panicf("%+v", err) + jww.FATAL.Panicf("Failed to unmarshal contact: %+v", err) } return c } diff --git a/interfaces/contact/contact.go b/interfaces/contact/contact.go index 242a758ab2d6ec721ed703c0c6c9c6603763868d..d5ac73094207e3c5dde1b2d35d5b2a80a5a95152 100644 --- a/interfaces/contact/contact.go +++ b/interfaces/contact/contact.go @@ -79,6 +79,12 @@ func (c Contact) Marshal() []byte { // Unmarshal decodes the byte slice produced by Contact.Marshal into a Contact. func Unmarshal(b []byte) (Contact, error) { + if len(b) < sizeByteLength*3+id.ArrIDLen { + return Contact{}, errors.Errorf("Length of provided buffer (%d) too "+ + "short; length must be at least %d.", + len(b), sizeByteLength*3+id.ArrIDLen) + } + c := Contact{DhPubKey: &cyclic.Int{}} var err error buff := bytes.NewBuffer(b)