fix panic in UnmarshalNebulaCertificate (#339)
This fixes a panic in UnmarshalNebulaCertificate when unmarshaling a payload with Details set to nil. Fixes: #332
This commit is contained in:
parent
0389596f66
commit
384b1166ea
|
@ -61,6 +61,10 @@ func UnmarshalNebulaCertificate(b []byte) (*NebulaCertificate, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rc.Details == nil {
|
||||||
|
return nil, fmt.Errorf("encoded Details was nil")
|
||||||
|
}
|
||||||
|
|
||||||
if len(rc.Details.Ips)%2 != 0 {
|
if len(rc.Details.Ips)%2 != 0 {
|
||||||
return nil, fmt.Errorf("encoded IPs should be in pairs, an odd number was found")
|
return nil, fmt.Errorf("encoded IPs should be in pairs, an odd number was found")
|
||||||
}
|
}
|
||||||
|
|
|
@ -499,6 +499,13 @@ func TestNebulaCertificate_Copy(t *testing.T) {
|
||||||
util.AssertDeepCopyEqual(t, c, cc)
|
util.AssertDeepCopyEqual(t, c, cc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalNebulaCertificate(t *testing.T) {
|
||||||
|
// Test that we don't panic with an invalid certificate (#332)
|
||||||
|
data := []byte("\x98\x00\x00")
|
||||||
|
_, err := UnmarshalNebulaCertificate(data)
|
||||||
|
assert.EqualError(t, err, "encoded Details was nil")
|
||||||
|
}
|
||||||
|
|
||||||
func newTestCaCert(before, after time.Time, ips, subnets []*net.IPNet, groups []string) (*NebulaCertificate, []byte, []byte, error) {
|
func newTestCaCert(before, after time.Time, ips, subnets []*net.IPNet, groups []string) (*NebulaCertificate, []byte, []byte, error) {
|
||||||
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
||||||
if before.IsZero() {
|
if before.IsZero() {
|
||||||
|
|
Loading…
Reference in New Issue