lnwire: when reading node aliases, properly check validity
In this commit, we ensure that when we read node aliases from the wire, we ensure that they're valid. Before this commit, we would read the raw bytes without checking for validity which could result in us writing in invalid node alias to disk. We've fixed this, and also updated the quickcheck tests to generate valid strings.
This commit is contained in:
1 parent
2e2d5fcf54
commit
0b10f4c4d8
3 files changed
+45
-11
No files matched your search
@@ -76,6 +76,11 @@ func (a addressType) AddrLen() uint16 {
|
||||
// serialization.
|
||||
func WriteElement(w io.Writer, element interface{}) error {
|
||||
switch e := element.(type) {
|
||||
case NodeAlias:
|
||||
if _, err := w.Write(e[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case ShortChanIDEncoding:
|
||||
var b [1]byte
|
||||
b[0] = uint8(e)
|
||||
@@ -429,6 +434,18 @@ func WriteElements(w io.Writer, elements ...interface{}) error {
|
||||
func ReadElement(r io.Reader, element interface{}) error {
|
||||
var err error
|
||||
switch e := element.(type) {
|
||||
case *NodeAlias:
|
||||
var a [32]byte
|
||||
if _, err := io.ReadFull(r, a[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
alias, err := NewNodeAlias(string(a[:]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*e = alias
|
||||
case *ShortChanIDEncoding:
|
||||
var b [1]uint8
|
||||
if _, err := r.Read(b[:]); err != nil {
|
||||
|
||||
Reference in new issue
Block a user