tlv: fail if parsed length doesn't match packet length

This commit is contained in:
lisa neigut 2019-03-24 19:35:25 -07:00 committed by Rusty Russell
parent 28c3f9ca21
commit d0f50c8690

View File

@ -850,6 +850,7 @@ tlv__type_impl_towire_template = """static void towire__{tlv_name}(const tal_t *
tlv__type_impl_fromwire_template = """static struct {tlv_name} *fromwire__{tlv_name}(const tal_t *ctx, const u8 **p, size_t *plen, const u16 *len) {{
\tu8 msg_type, msg_len;
\tsize_t start_len = *plen;
\tif (*plen < *len)
\t\treturn NULL;
@ -873,7 +874,7 @@ tlv__type_impl_fromwire_template = """static struct {tlv_name} *fromwire__{tlv_n
\t\t\t*plen -= msg_len;
\t\t}}
\t}}
\tif (!*p) {{
\tif (!*p || start_len - *plen != *len) {{
\t\ttal_free({tlv_name});
\t\treturn NULL;
\t}}