mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
Avoid undefined behaviour in eq_var(p1, p2, field)
memcmp((p1)->field, (p2)->field, ...) results in undefined behaviour if (p1)->field or (p2)->field is NULL. This holds also when tal_count((p1)->field) * sizeof(*(p1)->field) == 0.
This commit is contained in:
parent
6757255ba4
commit
7b80e5b66c
@ -68,7 +68,8 @@ static void set_pubkey(struct pubkey *key)
|
||||
sizeof((p1)->field)) == 0)
|
||||
|
||||
#define eq_var(p1, p2, field) \
|
||||
(tal_count((p1)->field) == tal_count((p2)->field) && memcmp((p1)->field, (p2)->field, tal_count((p1)->field) * sizeof(*(p1)->field)) == 0)
|
||||
(tal_count((p1)->field) == tal_count((p2)->field) \
|
||||
&& (tal_count((p1)->field) == 0 || memcmp((p1)->field, (p2)->field, tal_len((p1)->field)) == 0))
|
||||
|
||||
/* Convenience structs for everyone! */
|
||||
struct msg_error {
|
||||
|
Loading…
Reference in New Issue
Block a user