]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cli: fix nft -i command crashes when try to input multi line command
authorGuruswamy Basavaiah <guru2018@gmail.com>
Sat, 7 Jun 2014 19:14:16 +0000 (00:44 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 10 Jun 2014 15:23:17 +0000 (17:23 +0200)
When try to input multiline command in "nft -i", it crashes.

Issue is, function cli_append_multiline() return null in case of
multiline command. But in the calling function cli_complete(),
cli_exit is getting called, which in turn calls
rl_callback_handler_remove() and the handler is getting removed.

 [root@localhost ~]# nft -i
 nft> add table filter
 nft> list table \

 readline: readline_callback_read_char() called with no handler!
 Aborted (core dumped)
 [root@localhost ~]#

After this patch, it shows:

 nft> list table \
 .... filter
 table ip filter {
 }
 nft>

The ".... " prompt is used to indicate a multiline command, similar to
what Python does.

Signed-off-by: Guruswamy Basavaiah <guru2018@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/cli.c

index 8875207d4c5977f9f55ff3ad9bf597ff4770cd02..f748a0e2cbf38c02937e4255fd849d91fd6a9c3e 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -66,6 +66,7 @@ static char *cli_append_multiline(char *line)
                multiline = line;
                rl_save_prompt();
                rl_clear_message();
+               rl_set_prompt(".... ");
        } else {
                len += strlen(multiline);
                s = xmalloc(len + 1);
@@ -89,13 +90,16 @@ static void cli_complete(char *line)
        const char *c;
        LIST_HEAD(msgs);
 
-       line = cli_append_multiline(line);
        if (line == NULL) {
                printf("\n");
                cli_exit();
-               return;
+               exit(0);
        }
 
+       line = cli_append_multiline(line);
+       if (line == NULL)
+               return;
+
        for (c = line; *c != '\0'; c++)
                if (!isspace(*c))
                        break;