lnwire: modify newAlias to truncate alias strings if too long

This commit is contained in:
Olaoluwa Osuntokun 2017-03-08 14:21:50 -08:00
parent f881e0a356
commit da09f4dcc4
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -39,12 +39,17 @@ func NewAlias(s string) (Alias, error) {
func newAlias(data []byte) (Alias, error) { func newAlias(data []byte) (Alias, error) {
var a [32]byte var a [32]byte
aliasEnd := len(data) rawAlias := data
for data[aliasEnd-1] == 0 && aliasEnd > 0 { if len(data) > aliasSpecLen {
rawAlias = data[:aliasSpecLen]
}
aliasEnd := len(rawAlias)
for rawAlias[aliasEnd-1] == 0 && aliasEnd > 0 {
aliasEnd-- aliasEnd--
} }
copy(a[:aliasEnd], data[:aliasEnd]) copy(a[:aliasEnd], rawAlias[:aliasEnd])
return Alias{ return Alias{
data: a, data: a,
@ -94,6 +99,8 @@ type NodeAnnouncement struct {
// maps and graphs // maps and graphs
RGBColor RGB RGBColor RGB
// TODO(roasbeef): add the global features here
// pad is used to reserve to additional bytes for future // pad is used to reserve to additional bytes for future
// usage. // usage.
pad uint16 pad uint16