Skip to content
Snippets Groups Projects
Commit a4f631ed authored by Jono Wenger's avatar Jono Wenger
Browse files

Check size of provided data to Contact marshal

parent 485e942e
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment