mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
gossipd: use array[32] not pointer for alias.
And use ARRAY_SIZE() everywhere which will break compile if it's not a literal array, plus assertions that it's the same length. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
6c54a22d63
commit
afc92dd757
@@ -1,3 +1,4 @@
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/asort/asort.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
@@ -84,7 +85,7 @@ struct daemon {
|
||||
/* Global features to list in node_announcement. */
|
||||
u8 *globalfeatures;
|
||||
|
||||
u8 alias[33];
|
||||
u8 alias[32];
|
||||
u8 rgb[3];
|
||||
|
||||
/* What we can actually announce. */
|
||||
@@ -1410,8 +1411,10 @@ static void append_node(const struct gossip_getnodes_entry ***nodes,
|
||||
} else {
|
||||
new->last_timestamp = n->last_timestamp;
|
||||
new->addresses = n->addresses;
|
||||
new->alias = n->alias;
|
||||
memcpy(new->color, n->rgb_color, 3);
|
||||
BUILD_ASSERT(ARRAY_SIZE(new->alias) == ARRAY_SIZE(n->alias));
|
||||
BUILD_ASSERT(ARRAY_SIZE(new->color) == ARRAY_SIZE(n->rgb_color));
|
||||
memcpy(new->alias, n->alias, ARRAY_SIZE(new->alias));
|
||||
memcpy(new->color, n->rgb_color, ARRAY_SIZE(new->color));
|
||||
}
|
||||
*tal_arr_expand(nodes) = new;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,6 @@ static struct node *new_node(struct routing_state *rstate,
|
||||
n = tal(rstate, struct node);
|
||||
n->id = *id;
|
||||
n->chans = tal_arr(n, struct chan *, 0);
|
||||
n->alias = NULL;
|
||||
n->gfeatures = NULL;
|
||||
n->node_announcement = NULL;
|
||||
n->node_announcement_index = 0;
|
||||
@@ -1306,9 +1305,8 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
|
||||
node->addresses = tal_steal(node, wireaddrs);
|
||||
|
||||
node->last_timestamp = timestamp;
|
||||
memcpy(node->rgb_color, rgb_color, 3);
|
||||
tal_free(node->alias);
|
||||
node->alias = tal_dup_arr(node, u8, alias, 32, 0);
|
||||
memcpy(node->rgb_color, rgb_color, ARRAY_SIZE(node->rgb_color));
|
||||
memcpy(node->alias, alias, ARRAY_SIZE(node->alias));
|
||||
tal_free(node->gfeatures);
|
||||
node->gfeatures = tal_steal(node, features);
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ struct node {
|
||||
struct chan *prev;
|
||||
} bfg[ROUTING_MAX_HOPS+1];
|
||||
|
||||
/* UTF-8 encoded alias as tal_arr, not zero terminated */
|
||||
u8 *alias;
|
||||
/* UTF-8 encoded alias, not zero terminated */
|
||||
u8 alias[32];
|
||||
|
||||
/* Color to be used when displaying the name */
|
||||
u8 rgb_color[3];
|
||||
|
||||
@@ -202,7 +202,10 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
||||
json_object_end(response);
|
||||
continue;
|
||||
}
|
||||
esc = json_escape(NULL, (const char *)nodes[i]->alias);
|
||||
esc = json_escape(NULL,
|
||||
take(tal_strndup(NULL,
|
||||
(const char *)nodes[i]->alias,
|
||||
ARRAY_SIZE(nodes[i]->alias))));
|
||||
json_add_escaped_string(response, "alias", take(esc));
|
||||
json_add_hex(response, "color",
|
||||
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <common/bolt11.h>
|
||||
#include <common/wireaddr.h>
|
||||
#include <lightningd/gossip_msg.h>
|
||||
@@ -20,7 +21,6 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
||||
entry->last_timestamp = fromwire_u64(pptr, max);
|
||||
if (entry->last_timestamp < 0) {
|
||||
entry->addresses = NULL;
|
||||
entry->alias = NULL;
|
||||
return entry;
|
||||
}
|
||||
numaddresses = fromwire_u8(pptr, max);
|
||||
@@ -33,10 +33,8 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* Make sure alias is NUL terminated */
|
||||
entry->alias = tal_arrz(entry, u8, fromwire_u8(pptr, max)+1);
|
||||
fromwire(pptr, max, entry->alias, tal_count(entry->alias)-1);
|
||||
fromwire(pptr, max, entry->color, sizeof(entry->color));
|
||||
fromwire(pptr, max, entry->alias, ARRAY_SIZE(entry->alias));
|
||||
fromwire(pptr, max, entry->color, ARRAY_SIZE(entry->color));
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -58,9 +56,8 @@ void towire_gossip_getnodes_entry(u8 **pptr,
|
||||
for (i=0; i<numaddresses; i++) {
|
||||
towire_wireaddr(pptr, &entry->addresses[i]);
|
||||
}
|
||||
towire_u8(pptr, tal_count(entry->alias));
|
||||
towire(pptr, entry->alias, tal_count(entry->alias));
|
||||
towire(pptr, entry->color, sizeof(entry->color));
|
||||
towire(pptr, entry->alias, ARRAY_SIZE(entry->alias));
|
||||
towire(pptr, entry->color, ARRAY_SIZE(entry->color));
|
||||
}
|
||||
|
||||
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
|
||||
|
||||
@@ -16,7 +16,7 @@ struct gossip_getnodes_entry {
|
||||
u8 *globalfeatures;
|
||||
s64 last_timestamp; /* -1 means never: following fields ignored */
|
||||
struct wireaddr *addresses;
|
||||
u8 *alias;
|
||||
u8 alias[32];
|
||||
u8 color[3];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user