MCPcopy Create free account
hub / github.com/ElementsProject/lightning / sanitize_error

Function sanitize_error

common/wire_error.c:81–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
82 struct channel_id *channel_id)
83{
84 struct channel_id dummy;
85 u8 *data;
86 size_t i;
87 bool warning;
88
89 if (!channel_id)
90 channel_id = &dummy;
91
92 if (fromwire_error(ctx, errmsg, channel_id, &data))
93 warning = false;
94 else if (fromwire_warning(ctx, errmsg, channel_id, &data))
95 warning = true;
96 else
97 return tal_fmt(ctx, "Invalid ERROR message '%s'",
98 tal_hex(ctx, errmsg));
99
100 /* BOLT #1:
101 *
102 * The receiving node:
103 *...
104 * - if `data` is not composed solely of printable ASCII characters
105 * (For reference: the printable character set includes byte values 32
106 * through 126, inclusive):
107 * - SHOULD NOT print out `data` verbatim.
108 */
109 for (i = 0; i < tal_count(data); i++) {
110 if (data[i] < 32 || data[i] > 127) {
111 /* Convert to hex, minus NUL term */
112 data = (u8 *)tal_hex(ctx, data);
113 tal_resize(&data, strlen((const char *)data));
114 break;
115 }
116 }
117
118 return tal_fmt(ctx, "%s%s%s: %.*s",
119 warning ? "warning" : "error",
120 channel_id_is_all(channel_id) ? "": " channel ",
121 channel_id_is_all(channel_id) ? ""
122 : type_to_string(tmpctx, struct channel_id, channel_id),
123 (int)tal_count(data), (char *)data);
124}

Callers 2

is_peer_errorFunction · 0.70
read_body_from_peer_doneFunction · 0.50

Calls 3

tal_hexFunction · 0.85
channel_id_is_allFunction · 0.85
type_to_stringClass · 0.70

Tested by

no test coverage detected