diff --git a/lightningd/options.c b/lightningd/options.c index a19ff5a28..0e10cec9e 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -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; diff --git a/tests/test_misc.py b/tests/test_misc.py index e10b8441b..6703cd972 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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():