| 116 | } |
| 117 | |
| 118 | char *sanitize_error(const tal_t *ctx, const u8 *errmsg, |
| 119 | struct channel_id *channel_id) |
| 120 | { |
| 121 | struct channel_id dummy; |
| 122 | u8 *data; |
| 123 | size_t i; |
| 124 | const char *tag; |
| 125 | |
| 126 | if (!channel_id) |
| 127 | channel_id = &dummy; |
| 128 | |
| 129 | if (fromwire_error(ctx, errmsg, channel_id, &data)) |
| 130 | tag = "ERROR"; |
| 131 | else if (fromwire_warning(ctx, errmsg, channel_id, &data)) |
| 132 | tag = "WARNING"; |
| 133 | else if (fromwire_tx_abort(ctx, errmsg, channel_id, &data)) |
| 134 | tag = "ABORT"; |
| 135 | else |
| 136 | return tal_fmt(ctx, "Invalid ERROR message '%s'", |
| 137 | tal_hex(ctx, errmsg)); |
| 138 | |
| 139 | /* BOLT #1: |
| 140 | * |
| 141 | * The receiving node: |
| 142 | *... |
| 143 | * - if `data` is not composed solely of printable ASCII characters |
| 144 | * (For reference: the printable character set includes byte values 32 |
| 145 | * through 126, inclusive): |
| 146 | * - SHOULD NOT print out `data` verbatim. |
| 147 | */ |
| 148 | for (i = 0; i < tal_count(data); i++) { |
| 149 | if (data[i] < 32 || data[i] > 127) { |
| 150 | /* Convert to hex, minus NUL term */ |
| 151 | data = (u8 *)tal_hex(ctx, data); |
| 152 | tal_resize(&data, strlen((const char *)data)); |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return tal_fmt(ctx, "%s%s%s: %.*s", |
| 158 | tag, |
| 159 | channel_id_is_all(channel_id) ? "": " channel ", |
| 160 | channel_id_is_all(channel_id) ? "" |
| 161 | : fmt_channel_id(tmpctx, channel_id), |
| 162 | (int)tal_count(data), (char *)data); |
| 163 | } |
| 164 | |
| 165 | const char *is_peer_warning(const tal_t *ctx, const u8 *msg) |
| 166 | { |
no test coverage detected