Skip to content

Commit 094bdef

Browse files
committed
lightningd: unescape log message strings received from plugins
Plugins can send arbitrary strings in "log" notifications. Lightningd was logging these strings without unescaping them, leading to ugly backslashes in the log. Unescape the strings before logging them. Changelog-Fixed: Log messages from plugins no longer contain an extra level of escaping.
1 parent 1361ddf commit 094bdef

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lightningd/plugin.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <ccan/ccan/tal/grab_file/grab_file.h>
44
#include <ccan/crc32c/crc32c.h>
55
#include <ccan/io/io.h>
6+
#include <ccan/json_escape/json_escape.h>
67
#include <ccan/mem/mem.h>
78
#include <ccan/opt/opt.h>
89
#include <ccan/pipecmd/pipecmd.h>
@@ -487,6 +488,7 @@ static const char *plugin_log_handle(struct plugin *plugin,
487488
{
488489
const jsmntok_t *msgtok, *leveltok;
489490
enum log_level level;
491+
const char *msg;
490492
bool call_notifier;
491493
msgtok = json_get_member(plugin->buffer, paramstok, "message");
492494
leveltok = json_get_member(plugin->buffer, paramstok, "level");
@@ -511,10 +513,15 @@ static const char *plugin_log_handle(struct plugin *plugin,
511513
json_tok_full(plugin->buffer, leveltok));
512514
}
513515

516+
msg = json_escape_unescape_len(tmpctx, plugin->buffer + msgtok->start,
517+
msgtok->end - msgtok->start);
518+
if (!msg)
519+
return tal_fmt(plugin, "Log notification from plugin has a \"message\" "
520+
"string containing an invalid escape sequence.");
521+
514522
call_notifier = (level == LOG_BROKEN || level == LOG_UNUSUAL)? true : false;
515523
/* FIXME: Let plugin specify node_id? */
516-
log_(plugin->log, level, NULL, call_notifier, "%.*s", msgtok->end - msgtok->start,
517-
plugin->buffer + msgtok->start);
524+
log_(plugin->log, level, NULL, call_notifier, "%s", msg);
518525
return NULL;
519526
}
520527

0 commit comments

Comments
 (0)