Browse Source

wire: Let the TLV _is_valid function actually return validity

I got this one wrong myself, since the function name implied a boolean
result. So I changed it to take the optional err_index as argument.
travis-debug
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
69c17d2d31
  1. 3
      lightningd/peer_htlcs.c
  2. 8
      tools/gen/header_template
  3. 14
      tools/gen/impl_template
  4. 3
      wallet/test/run-wallet.c

3
lightningd/peer_htlcs.c

@ -793,7 +793,8 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
* correctly. */
static bool htlc_accepted_can_continue(struct route_step *rs)
{
if (rs->type == SPHINX_TLV_PAYLOAD && !tlv_payload_is_valid(rs->payload.tlv)) {
if (rs->type == SPHINX_TLV_PAYLOAD &&
!tlv_payload_is_valid(rs->payload.tlv, NULL)) {
SUPERVERBOSE("Encoding of TLV payload is invalid");
return false;
}

8
tools/gen/header_template

@ -75,10 +75,12 @@ bool fromwire_${tlv.name}(const u8 **cursor, size_t *max, struct ${tlv.struct_na
* - Types must be in monotonic non-repeating order
* - We must understand all even types
*
* Returns the index of the field that was invalid, or -1 if the stream is
* valid.
* Returns false if an error was detected, otherwise returns true. If err_index
* is non-null and we detect an error it is set to the index of the first error
* detected.
*/
int ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record);
bool ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record,
size_t *err_index);
% if tlv.name in options.expose_tlv_type:
#define TLVS_${tlv.name.upper()}_ARRAY_SIZE ${len(tlv.messages)}

14
tools/gen/impl_template

@ -306,7 +306,7 @@ fail:
return false;
}
int ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record)
bool ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record, size_t *err_index)
{
size_t numfields = tal_count(record->fields);
bool first = true;
@ -321,8 +321,10 @@ int ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record)
* - otherwise, if `type` is odd:
* - MUST discard the next `length` bytes.
*/
SUPERVERBOSE("Unknown even type in TLV");
return i;
SUPERVERBOSE("unknown even");
if (err_index != NULL)
*err_index = i;
return false;
} else if (!first && f->numtype <= prev_type) {
/* BOLT #1:
* - if decoded `type`s are not monotonically-increasing:
@ -332,12 +334,14 @@ int ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record)
SUPERVERBOSE("duplicate tlv type");
else
SUPERVERBOSE("invalid ordering");
return i;
if (err_index != NULL)
*err_index = i;
return false;
}
first = false;
prev_type = f->numtype;
}
return -1;
return true;
}
% endfor ## END TLV's

3
wallet/test/run-wallet.c

@ -546,7 +546,8 @@ void subd_req_(const tal_t *ctx UNNEEDED,
void subd_send_msg(struct subd *sd UNNEEDED, const u8 *msg_out UNNEEDED)
{ fprintf(stderr, "subd_send_msg called!\n"); abort(); }
/* Generated stub for tlv_payload_is_valid */
int tlv_payload_is_valid(const struct tlv_tlv_payload *record UNNEEDED)
bool tlv_payload_is_valid(const struct tlv_tlv_payload *record UNNEEDED,
size_t *err_index UNNEEDED)
{ fprintf(stderr, "tlv_payload_is_valid called!\n"); abort(); }
/* Generated stub for topology_add_sync_waiter_ */
void topology_add_sync_waiter_(const tal_t *ctx UNNEEDED,

Loading…
Cancel
Save