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
+12
-7
@@ -41,6 +41,17 @@ var (
|
||||
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
|
||||
)
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
func randAlias(r *rand.Rand) NodeAlias {
|
||||
var a NodeAlias
|
||||
for i := range a {
|
||||
a[i] = letterBytes[r.Intn(len(letterBytes))]
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func randPubKey() (*btcec.PublicKey, error) {
|
||||
priv, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
@@ -551,17 +562,11 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
v[0] = reflect.ValueOf(req)
|
||||
},
|
||||
MsgNodeAnnouncement: func(v []reflect.Value, r *rand.Rand) {
|
||||
var a [32]byte
|
||||
if _, err := r.Read(a[:]); err != nil {
|
||||
t.Fatalf("unable to generate alias: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
req := NodeAnnouncement{
|
||||
Features: randRawFeatureVector(r),
|
||||
Timestamp: uint32(r.Int31()),
|
||||
Alias: a,
|
||||
Alias: randAlias(r),
|
||||
RGBColor: color.RGBA{
|
||||
R: uint8(r.Int31()),
|
||||
G: uint8(r.Int31()),
|
||||
|
||||
Reference in new issue
Block a user