Browse Source

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.
travis-debug
Rusty Russell 5 years ago
parent
commit
14997f6237
  1. 6
      lightningd/options.c
  2. 5
      tests/test_misc.py

6
lightningd/options.c

@ -1112,7 +1112,8 @@ static void add_config(struct lightningd *ld,
if (opt->desc == opt_hidden) { if (opt->desc == opt_hidden) {
/* Ignore hidden options (deprecated) */ /* Ignore hidden options (deprecated) */
} else if (opt->show) { } 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); opt->show(buf, opt->u.carg);
if (streq(buf, "true") || streq(buf, "false") 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 */ /* opt_show_charp surrounds with "", strip them */
if (strstarts(buf, "\"")) { if (strstarts(buf, "\"")) {
buf[strlen(buf)-1] = '\0'; char *end = strrchr(buf, '"');
memmove(end, end + 1, strlen(end));
answer = buf + 1; answer = buf + 1;
} else } else
answer = buf; answer = buf;

5
tests/test_misc.py

@ -732,13 +732,16 @@ def test_address(node_factory):
def test_listconfigs(node_factory, bitcoind, chainparams): 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() configs = l1.rpc.listconfigs()
# See utils.py # See utils.py
assert configs['allow-deprecated-apis'] is False assert configs['allow-deprecated-apis'] is False
assert configs['network'] == chainparams['name'] assert configs['network'] == chainparams['name']
assert configs['ignore-fee-limits'] is False 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. # Test one at a time.
for c in configs.keys(): for c in configs.keys():

Loading…
Cancel
Save