Skip to content

Commit b00b351

Browse files
committed
invoice: Disable overlong description.
See: #1020 (review) Fixes: #1014
1 parent 8787766 commit b00b351

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lightningd/invoice.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static void json_invoice(struct command *cmd,
106106
jsmntok_t *msatoshi, *label, *desc, *exp;
107107
u64 *msatoshi_val;
108108
const char *label_val;
109+
const char *desc_val;
109110
struct json_result *response = new_json_result(cmd);
110111
struct wallet *wallet = cmd->ld->wallet;
111112
struct bolt11 *b11;
@@ -148,6 +149,19 @@ static void json_invoice(struct command *cmd,
148149
INVOICE_MAX_LABEL_LEN);
149150
return;
150151
}
152+
/* description */
153+
if (desc->end - desc->start >= BOLT11_FIELD_BYTE_LIMIT) {
154+
command_fail(cmd,
155+
"Descriptions greater than %d bytes "
156+
"not yet supported "
157+
"(description length %d)",
158+
BOLT11_FIELD_BYTE_LIMIT,
159+
desc->end - desc->start);
160+
return;
161+
}
162+
desc_val = tal_strndup(cmd, buffer + desc->start,
163+
desc->end - desc->start);
164+
/* expiry */
151165
if (exp && !json_tok_u64(buffer, exp, &expiry)) {
152166
command_fail(cmd, "Expiry '%.*s' invalid seconds",
153167
exp->end - exp->start,
@@ -172,13 +186,8 @@ static void json_invoice(struct command *cmd,
172186
b11->receiver_id = cmd->ld->id;
173187
b11->min_final_cltv_expiry = cmd->ld->config.cltv_final;
174188
b11->expiry = expiry;
175-
if (desc->end - desc->start >= BOLT11_FIELD_BYTE_LIMIT) {
176-
b11->description_hash = tal(b11, struct sha256);
177-
sha256(b11->description_hash, buffer + desc->start,
178-
desc->end - desc->start);
179-
} else
180-
b11->description = tal_strndup(b11, buffer + desc->start,
181-
desc->end - desc->start);
189+
b11->description = tal_steal(b11, desc_val);
190+
b11->description_hash = NULL;
182191

183192
/* FIXME: add private routes if necessary! */
184193
b11enc = bolt11_encode(cmd, b11, false, hsm_sign_b11, cmd->ld);
@@ -190,8 +199,6 @@ static void json_invoice(struct command *cmd,
190199
json_add_u64(response, "expiry_time", invoice->expiry_time);
191200
json_add_u64(response, "expires_at", invoice->expiry_time);
192201
json_add_string(response, "bolt11", b11enc);
193-
if (b11->description_hash)
194-
json_add_string(response, "description", b11->description);
195202
json_object_end(response);
196203

197204
command_success(cmd, response);

0 commit comments

Comments
 (0)