mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
lightningd: fix handling of truncated config options.
Do the same thing '--help' does with them; append `...`. Valgrind noticed that we weren't NUL-terminarting if answer was over 78 characters. Changelog-Fixed: JSONRPC: listconfigs appends '...' to truncated config options.
This commit is contained in:
parent
f5831e5d10
commit
14997f6237
@ -1112,7 +1112,8 @@ static void add_config(struct lightningd *ld,
|
||||
if (opt->desc == opt_hidden) {
|
||||
/* Ignore hidden options (deprecated) */
|
||||
} else if (opt->show) {
|
||||
char *buf = tal_arr(name0, char, OPT_SHOW_LEN+1);
|
||||
char buf[OPT_SHOW_LEN + sizeof("...")];
|
||||
strcpy(buf + OPT_SHOW_LEN, "...");
|
||||
opt->show(buf, opt->u.carg);
|
||||
|
||||
if (streq(buf, "true") || streq(buf, "false")
|
||||
@ -1126,7 +1127,8 @@ static void add_config(struct lightningd *ld,
|
||||
|
||||
/* opt_show_charp surrounds with "", strip them */
|
||||
if (strstarts(buf, "\"")) {
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
char *end = strrchr(buf, '"');
|
||||
memmove(end, end + 1, strlen(end));
|
||||
answer = buf + 1;
|
||||
} else
|
||||
answer = buf;
|
||||
|
@ -732,13 +732,16 @@ def test_address(node_factory):
|
||||
|
||||
|
||||
def test_listconfigs(node_factory, bitcoind, chainparams):
|
||||
l1 = node_factory.get_node()
|
||||
# Make extremely long entry, check it works
|
||||
l1 = node_factory.get_node(options={'log-prefix': 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'})
|
||||
|
||||
configs = l1.rpc.listconfigs()
|
||||
# See utils.py
|
||||
assert configs['allow-deprecated-apis'] is False
|
||||
assert configs['network'] == chainparams['name']
|
||||
assert configs['ignore-fee-limits'] is False
|
||||
assert configs['ignore-fee-limits'] is False
|
||||
assert configs['log-prefix'] == 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...'
|
||||
|
||||
# Test one at a time.
|
||||
for c in configs.keys():
|
||||
|
Loading…
Reference in New Issue
Block a user