Browse Source

utf8: handle UTF-8 arrays.

BOLT 12 introduces this as a new fundamental type, which lets us easily
validate them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
fix-mocks
Rusty Russell 4 years ago
parent
commit
a11edebb7c
  1. 2
      channeld/channeld_wiregen.c
  2. 2
      channeld/channeld_wiregen.h
  3. 2
      closingd/closingd_wiregen.c
  4. 2
      closingd/closingd_wiregen.h
  5. 2
      common/peer_status_wiregen.c
  6. 2
      common/peer_status_wiregen.h
  7. 2
      common/status_wiregen.c
  8. 2
      common/status_wiregen.h
  9. 2
      connectd/connectd_gossipd_wiregen.c
  10. 2
      connectd/connectd_gossipd_wiregen.h
  11. 2
      connectd/connectd_wiregen.c
  12. 2
      connectd/connectd_wiregen.h
  13. 2
      gossipd/gossip_store_wiregen.c
  14. 2
      gossipd/gossip_store_wiregen.h
  15. 2
      gossipd/gossipd_peerd_wiregen.c
  16. 2
      gossipd/gossipd_peerd_wiregen.h
  17. 2
      gossipd/gossipd_wiregen.c
  18. 2
      gossipd/gossipd_wiregen.h
  19. 2
      hsmd/hsmd_wiregen.c
  20. 2
      hsmd/hsmd_wiregen.h
  21. 2
      onchaind/onchaind_wiregen.c
  22. 2
      onchaind/onchaind_wiregen.h
  23. 2
      openingd/dualopend_wiregen.c
  24. 2
      openingd/dualopend_wiregen.h
  25. 2
      openingd/openingd_wiregen.c
  26. 2
      openingd/openingd_wiregen.h
  27. 6
      tools/generate-wire.py
  28. 2
      wire/common_wiregen.c
  29. 2
      wire/common_wiregen.h
  30. 7
      wire/fromwire.c
  31. 2
      wire/onion_printgen.c
  32. 2
      wire/onion_printgen.h
  33. 2
      wire/onion_wiregen.c
  34. 2
      wire/onion_wiregen.h
  35. 2
      wire/peer_printgen.c
  36. 2
      wire/peer_printgen.h
  37. 2
      wire/peer_wiregen.c
  38. 2
      wire/peer_wiregen.h
  39. 6
      wire/towire.c
  40. 3
      wire/wire.h

2
channeld/channeld_wiregen.c

@ -1248,4 +1248,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
}
return cursor != NULL;
}
// SHA256STAMP:d9bd64dc170dd8cbc8329c2ae59bd251d7057f948f7ef527b8e769cfe267e937
// SHA256STAMP:5fc565464be5cacb6e6ef163e41b1eee4ca3276848a30a3892f6f808f1b4c480

2
channeld/channeld_wiregen.h

@ -246,4 +246,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */
// SHA256STAMP:d9bd64dc170dd8cbc8329c2ae59bd251d7057f948f7ef527b8e769cfe267e937
// SHA256STAMP:5fc565464be5cacb6e6ef163e41b1eee4ca3276848a30a3892f6f808f1b4c480

2
closingd/closingd_wiregen.c

@ -201,4 +201,4 @@ bool fromwire_closingd_complete(const void *p)
return false;
return cursor != NULL;
}
// SHA256STAMP:e0edc6ae34e0b58fbc2f33b2a388ca55a4821422fcfafee098dc19b5e480b3d5
// SHA256STAMP:4c5c7cce1af5d1e90d298e286ca885d6153237aba8d52a427bda58d4d7094f3b

2
closingd/closingd_wiregen.h

@ -56,4 +56,4 @@ bool fromwire_closingd_complete(const void *p);
#endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */
// SHA256STAMP:e0edc6ae34e0b58fbc2f33b2a388ca55a4821422fcfafee098dc19b5e480b3d5
// SHA256STAMP:4c5c7cce1af5d1e90d298e286ca885d6153237aba8d52a427bda58d4d7094f3b

2
common/peer_status_wiregen.c

@ -80,4 +80,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_
fromwire_u8_array(&cursor, &plen, *error_for_them, len);
return cursor != NULL;
}
// SHA256STAMP:612d608c07fc296757d24389b7a459a3f9b72285fafe342a5c8cd42fd3ec88af
// SHA256STAMP:3190167a077593b13e10bab07e02e8e9666ea73f136a2860eca9618e1771593f

2
common/peer_status_wiregen.h

@ -34,4 +34,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_
#endif /* LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H */
// SHA256STAMP:612d608c07fc296757d24389b7a459a3f9b72285fafe342a5c8cd42fd3ec88af
// SHA256STAMP:3190167a077593b13e10bab07e02e8e9666ea73f136a2860eca9618e1771593f

2
common/status_wiregen.c

@ -191,4 +191,4 @@ bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm,
*happenings = fromwire_wirestring(ctx, &cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:022530b0ae77beecb3645526079c8727101593bd2a5881ecf556c9538c135d98
// SHA256STAMP:9d3b2dd6c7771732bc056bf348b3593534bbc3fc1dc0181867e60790cc087155

2
common/status_wiregen.h

@ -53,4 +53,4 @@ bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm,
#endif /* LIGHTNING_COMMON_STATUS_WIREGEN_H */
// SHA256STAMP:022530b0ae77beecb3645526079c8727101593bd2a5881ecf556c9538c135d98
// SHA256STAMP:9d3b2dd6c7771732bc056bf348b3593534bbc3fc1dc0181867e60790cc087155

2
connectd/connectd_gossipd_wiregen.c

@ -161,4 +161,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi
fromwire_wireaddr(&cursor, &plen, *addrs + i);
return cursor != NULL;
}
// SHA256STAMP:6d306e062eb24755e6585d52f4a06e9a74af50ac14e03546aaf2d8ed0c9242b5
// SHA256STAMP:7039ba295c9a73c166b91ae1f7e81207759463feb5b425471a5af1bd8d4f8485

2
connectd/connectd_gossipd_wiregen.h

@ -54,4 +54,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi
#endif /* LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H */
// SHA256STAMP:6d306e062eb24755e6585d52f4a06e9a74af50ac14e03546aaf2d8ed0c9242b5
// SHA256STAMP:7039ba295c9a73c166b91ae1f7e81207759463feb5b425471a5af1bd8d4f8485

2
connectd/connectd_wiregen.c

@ -406,4 +406,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:3874bf7cdd0e406217e6e59e43fab1e287f61e1e027009e352646c24baab0568
// SHA256STAMP:f9c15e7c9b2eb072f2489fa3db3b993b2fd8cbed7d0d24d9b1ca200d04de8d3d

2
connectd/connectd_wiregen.h

@ -103,4 +103,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H */
// SHA256STAMP:3874bf7cdd0e406217e6e59e43fab1e287f61e1e027009e352646c24baab0568
// SHA256STAMP:f9c15e7c9b2eb072f2489fa3db3b993b2fd8cbed7d0d24d9b1ca200d04de8d3d

2
gossipd/gossip_store_wiregen.c

@ -187,4 +187,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str
fromwire_u8_array(&cursor, &plen, *features, flen);
return cursor != NULL;
}
// SHA256STAMP:6e03c4b93e8b0a2c6fd61f3bd0d23bf4898dd38d109c5a401ba05e9e4e68267e
// SHA256STAMP:166d11ef9f76018daa2e05724c3a1a50d50667344bd4f0c7f093d57a66c408ba

2
gossipd/gossip_store_wiregen.h

@ -58,4 +58,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str
#endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H */
// SHA256STAMP:6e03c4b93e8b0a2c6fd61f3bd0d23bf4898dd38d109c5a401ba05e9e4e68267e
// SHA256STAMP:166d11ef9f76018daa2e05724c3a1a50d50667344bd4f0c7f093d57a66c408ba

2
gossipd/gossipd_peerd_wiregen.c

@ -187,4 +187,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p
fromwire_u8_array(&cursor, &plen, *cannount, len);
return cursor != NULL;
}
// SHA256STAMP:18c1c9ce4dfed92c5fc6809cf716bf31cbb39fb8db124d43ead013088aff8b7c
// SHA256STAMP:9d7f638f7e34c39ed06ea7150be7c1ae51f038da22d3e842160c5f472cfa40f0

2
gossipd/gossipd_peerd_wiregen.h

@ -64,4 +64,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p
#endif /* LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H */
// SHA256STAMP:18c1c9ce4dfed92c5fc6809cf716bf31cbb39fb8db124d43ead013088aff8b7c
// SHA256STAMP:9d7f638f7e34c39ed06ea7150be7c1ae51f038da22d3e842160c5f472cfa40f0

2
gossipd/gossipd_wiregen.c

@ -857,4 +857,4 @@ bool fromwire_gossipd_new_blockheight(const void *p, u32 *blockheight)
*blockheight = fromwire_u32(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:b9a39b664d2a598fb69e39147ff5d66e1abe5c9493db4a511bba6d2ecbcdfe29
// SHA256STAMP:ae8bf4f19cc3dd086b9a20b8bc034d93d8ef066e901279de09fe2fd189f1344b

2
gossipd/gossipd_wiregen.h

@ -199,4 +199,4 @@ bool fromwire_gossipd_new_blockheight(const void *p, u32 *blockheight);
#endif /* LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H */
// SHA256STAMP:b9a39b664d2a598fb69e39147ff5d66e1abe5c9493db4a511bba6d2ecbcdfe29
// SHA256STAMP:ae8bf4f19cc3dd086b9a20b8bc034d93d8ef066e901279de09fe2fd189f1344b

2
hsmd/hsmd_wiregen.c

@ -1214,4 +1214,4 @@ bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const void *p
fromwire_u8_array(&cursor, &plen, *script, script_len);
return cursor != NULL;
}
// SHA256STAMP:bbfe5b669e8a931aa5426be248dc8320a48f22fd5231612dfc1ce22a6f300668
// SHA256STAMP:02b3951c8bdb27997f5a30ebcf2e174cb99d6089d889b94da925fd674fca653f

2
hsmd/hsmd_wiregen.h

@ -271,4 +271,4 @@ bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const void *p
#endif /* LIGHTNING_HSMD_HSMD_WIREGEN_H */
// SHA256STAMP:bbfe5b669e8a931aa5426be248dc8320a48f22fd5231612dfc1ce22a6f300668
// SHA256STAMP:02b3951c8bdb27997f5a30ebcf2e174cb99d6089d889b94da925fd674fca653f

2
onchaind/onchaind_wiregen.c

@ -635,4 +635,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt
fromwire_chain_coin_mvt(&cursor, &plen, mvt);
return cursor != NULL;
}
// SHA256STAMP:3e82025758cfaf2467242d259ac50c2ca66de3a8eabc1ff905aeb3effca0e5c7
// SHA256STAMP:8e5cf0f64250387b58b21ed885599a9216a3d2f4aee8cf7b7901965c5a197250

2
onchaind/onchaind_wiregen.h

@ -161,4 +161,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt
#endif /* LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H */
// SHA256STAMP:3e82025758cfaf2467242d259ac50c2ca66de3a8eabc1ff905aeb3effca0e5c7
// SHA256STAMP:8e5cf0f64250387b58b21ed885599a9216a3d2f4aee8cf7b7901965c5a197250

2
openingd/dualopend_wiregen.c

@ -485,4 +485,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:48dcbf79652c7cde9ad129b137cc60be72be6232ed20a8c2675a00f427ab6f91
// SHA256STAMP:435564ffcea3302152e316a659eb30091a72b0d81f0959bea22ecb7e11f23223

2
openingd/dualopend_wiregen.h

@ -109,4 +109,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */
// SHA256STAMP:48dcbf79652c7cde9ad129b137cc60be72be6232ed20a8c2675a00f427ab6f91
// SHA256STAMP:435564ffcea3302152e316a659eb30091a72b0d81f0959bea22ecb7e11f23223

2
openingd/openingd_wiregen.c

@ -579,4 +579,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:2d53106a700f181fa46b0c82a9cb65e823bb9c39ec116adf72d24b52e27e05b6
// SHA256STAMP:4690dd9aa4d8d79f999f90336a18d7682bf7910227f3191af4f2efaaa3ec4f0a

2
openingd/openingd_wiregen.h

@ -121,4 +121,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H */
// SHA256STAMP:2d53106a700f181fa46b0c82a9cb65e823bb9c39ec116adf72d24b52e27e05b6
// SHA256STAMP:4690dd9aa4d8d79f999f90336a18d7682bf7910227f3191af4f2efaaa3ec4f0a

6
tools/generate-wire.py

@ -204,6 +204,7 @@ class Type(FieldSet):
'bool',
'secp256k1_ecdsa_signature',
'secp256k1_ecdsa_recoverable_signature',
'utf8',
'wirestring',
'errcode_t',
'bigsize',
@ -318,9 +319,10 @@ class Type(FieldSet):
return prefix + self.struct_name()
# We only accelerate the u8 case: it's common and trivial.
# We accelerate the u8 case: it's common and trivial.
# We handle the utf8 case so we can be sure it's actually a UTF-8 string.
def has_array_helper(self):
return self.name in ['u8']
return self.name in ['u8', 'utf8']
def struct_name(self):
if self.is_tlv():

2
wire/common_wiregen.c

@ -100,4 +100,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg)
fromwire_u8_array(&cursor, &plen, *msg, msg_len);
return cursor != NULL;
}
// SHA256STAMP:83d7a6305b316f37ff2278d9c4fb2c9efa9381688b78b84dd0a8928ca67e1563
// SHA256STAMP:d4c8c4004743b7b2406498243779786933b5f6b5fa900fbb889acae528bdbded

2
wire/common_wiregen.h

@ -41,4 +41,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg);
#endif /* LIGHTNING_WIRE_COMMON_WIREGEN_H */
// SHA256STAMP:83d7a6305b316f37ff2278d9c4fb2c9efa9381688b78b84dd0a8928ca67e1563
// SHA256STAMP:d4c8c4004743b7b2406498243779786933b5f6b5fa900fbb889acae528bdbded

7
wire/fromwire.c

@ -207,6 +207,13 @@ void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num)
fromwire(cursor, max, arr, num);
}
void fromwire_utf8_array(const u8 **cursor, size_t *max, char *arr, size_t num)
{
fromwire(cursor, max, arr, num);
if (!utf8_check(arr, num))
fromwire_fail(cursor, max);
}
u8 *fromwire_tal_arrn(const tal_t *ctx,
const u8 **cursor, size_t *max, size_t num)
{

2
wire/onion_printgen.c

@ -653,4 +653,4 @@ void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_tlv_payload, ARRAY_SIZE(print_tlvs_tlv_payload));
}
}
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede
// SHA256STAMP:c481f839b27a61a861400d0ad6001f02dbd2bf1e0bb56db05d0cc7bdf2186fc2

2
wire/onion_printgen.h

@ -57,4 +57,4 @@ void printwire_mpp_timeout(const char *fieldname, const u8 *cursor);
#endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede
// SHA256STAMP:c481f839b27a61a861400d0ad6001f02dbd2bf1e0bb56db05d0cc7bdf2186fc2

2
wire/onion_wiregen.c

@ -697,4 +697,4 @@ bool fromwire_mpp_timeout(const void *p)
return false;
return cursor != NULL;
}
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede
// SHA256STAMP:c481f839b27a61a861400d0ad6001f02dbd2bf1e0bb56db05d0cc7bdf2186fc2

2
wire/onion_wiregen.h

@ -207,4 +207,4 @@ bool fromwire_mpp_timeout(const void *p);
#endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede
// SHA256STAMP:c481f839b27a61a861400d0ad6001f02dbd2bf1e0bb56db05d0cc7bdf2186fc2

2
wire/peer_printgen.c

@ -2036,4 +2036,4 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_reply_channel_range_tlvs, ARRAY_SIZE(print_tlvs_reply_channel_range_tlvs));
}
}
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92
// SHA256STAMP:433cf5b6bd1df5f251b4be28aa38e2e6aa4c15432f3ae103f69591fd970188bd

2
wire/peer_printgen.h

@ -70,4 +70,4 @@ void printwire_gossip_timestamp_filter(const char *fieldname, const u8 *cursor);
void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor, size_t *plen);
void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen);
#endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92
// SHA256STAMP:433cf5b6bd1df5f251b4be28aa38e2e6aa4c15432f3ae103f69591fd970188bd

2
wire/peer_wiregen.c

@ -1630,4 +1630,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec
*htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92
// SHA256STAMP:433cf5b6bd1df5f251b4be28aa38e2e6aa4c15432f3ae103f69591fd970188bd

2
wire/peer_wiregen.h

@ -595,4 +595,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec
#endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92
// SHA256STAMP:433cf5b6bd1df5f251b4be28aa38e2e6aa4c15432f3ae103f69591fd970188bd

6
wire/towire.c

@ -123,6 +123,12 @@ void towire_u8_array(u8 **pptr, const u8 *arr, size_t num)
towire(pptr, arr, num);
}
void towire_utf8_array(u8 **pptr, const char *arr, size_t num)
{
assert(utf8_check(arr, num));
towire(pptr, arr, num);
}
void towire_pad(u8 **pptr, size_t num)
{
/* Simply insert zeros. */

3
wire/wire.h

@ -14,6 +14,7 @@ struct siphash_seed;
/* Makes generate-wire.py work */
typedef char wirestring;
typedef char utf8;
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
int fromwire_peektype(const u8 *cursor);
@ -38,6 +39,7 @@ void towire_bool(u8 **pptr, bool v);
void towire_errcode_t(u8 **pptr, errcode_t v);
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
void towire_utf8_array(u8 **pptr, const char *arr, size_t num);
void towire_wirestring(u8 **pptr, const char *str);
void towire_siphash_seed(u8 **cursor, const struct siphash_seed *seed);
@ -62,6 +64,7 @@ void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd
void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num);
void fromwire_utf8_array(const u8 **cursor, size_t *max, char *arr, size_t num);
u8 *fromwire_tal_arrn(const tal_t *ctx,
const u8 **cursor, size_t *max, size_t num);
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max);

Loading…
Cancel
Save