| 87 | } |
| 88 | |
| 89 | static u64 fromwire_tlv_uint(const u8 **cursor, size_t *max, size_t maxlen) |
| 90 | { |
| 91 | u8 bytes[8]; |
| 92 | size_t length; |
| 93 | be64 val; |
| 94 | |
| 95 | assert(maxlen <= sizeof(bytes)); |
| 96 | |
| 97 | /* BOLT #1: |
| 98 | * |
| 99 | * - if `length` is not exactly equal to that required for the |
| 100 | * known encoding for `type`: |
| 101 | * - MUST fail to parse the `tlv_stream`. |
| 102 | */ |
| 103 | length = *max; |
| 104 | if (length > maxlen) { |
| 105 | SUPERVERBOSE("greater than encoding length"); |
| 106 | fromwire_fail(cursor, max); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | memset(bytes, 0, sizeof(bytes)); |
| 111 | fromwire(cursor, max, bytes + sizeof(bytes) - length, length); |
| 112 | |
| 113 | /* BOLT #1: |
| 114 | * - if variable-length fields within the known encoding for `type` are |
| 115 | * not minimal: |
| 116 | * - MUST fail to parse the `tlv_stream`. |
| 117 | */ |
| 118 | if (length > 0 && bytes[sizeof(bytes) - length] == 0) { |
| 119 | SUPERVERBOSE("not minimal"); |
| 120 | fromwire_fail(cursor, max); |
| 121 | return 0; |
| 122 | } |
| 123 | BUILD_ASSERT(sizeof(val) == sizeof(bytes)); |
| 124 | memcpy(&val, bytes, sizeof(bytes)); |
| 125 | return be64_to_cpu(val); |
| 126 | } |
| 127 | |
| 128 | u16 fromwire_tu16(const u8 **cursor, size_t *max) |
| 129 | { |
no test coverage detected