diff mbox

[nftables] fix nft -i command crashes when try to input multi line command

Message ID CAHSpA5_tm8PJKSCYwo4RObrzm25tGNX+j_7=K8ySB5+NdK0N9g@mail.gmail.com
State Superseded
Headers show

Commit Message

Guruswamy Basavaiah June 7, 2014, 7:14 p.m. UTC
Hello,
 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.


Signed-off-by: Guruswamy Basavaiah <guru2018@gmail.com>
---
---
 src/cli.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Pablo Neira Ayuso June 10, 2014, 10:55 a.m. UTC | #1
On Sun, Jun 08, 2014 at 12:44:16AM +0530, Guruswamy B wrote:
> Hello,
>  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.

Could you include an example on how to reproduce the crash that I can
append to this patch description?

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guruswamy Basavaiah June 10, 2014, 11:05 a.m. UTC | #2
Hello,
 Steps to reproduce.
 [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 ~]#


Guru

On 10 June 2014 16:25, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Sun, Jun 08, 2014 at 12:44:16AM +0530, Guruswamy B wrote:
>> Hello,
>>  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.
>
> Could you include an example on how to reproduce the crash that I can
> append to this patch description?
>
> Thanks.
Pablo Neira Ayuso June 10, 2014, 11:22 a.m. UTC | #3
On Tue, Jun 10, 2014 at 04:35:09PM +0530, Guruswamy Basavaiah wrote:
> Hello,
>  Steps to reproduce.
>  [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 ~]#

I see, thanks.

Perhaps we can do something similar to python, I'd suggest:

nft> list table \
.... filter
table ip filter {
        chain INPUT {
                type filter hook input priority 0;
        }
}

I mean use "...." if we are in the context of a multiline.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/cli.c b/src/cli.c
index 8875207..c0051a5 100644
--- 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,12 +90,15 @@  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))