netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nftables PATCH] fix nft -i command crashes when try to input multi line command
@ 2014-06-07 19:14 Guruswamy B
  2014-06-10 10:55 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Guruswamy B @ 2014-06-07 19:14 UTC (permalink / raw)
  To: netfilter-devel

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(-)

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))
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [nftables PATCH] fix nft -i command crashes when try to input multi line command
  2014-06-07 19:14 [nftables PATCH] fix nft -i command crashes when try to input multi line command Guruswamy B
@ 2014-06-10 10:55 ` Pablo Neira Ayuso
  2014-06-10 11:05   ` Guruswamy Basavaiah
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-10 10:55 UTC (permalink / raw)
  To: Guruswamy B; +Cc: netfilter-devel

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [nftables PATCH] fix nft -i command crashes when try to input multi line command
  2014-06-10 10:55 ` Pablo Neira Ayuso
@ 2014-06-10 11:05   ` Guruswamy Basavaiah
  2014-06-10 11:22     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Guruswamy Basavaiah @ 2014-06-10 11:05 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

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.



-- 
Guruswamy Basavaiah

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [nftables PATCH] fix nft -i command crashes when try to input multi line command
  2014-06-10 11:05   ` Guruswamy Basavaiah
@ 2014-06-10 11:22     ` Pablo Neira Ayuso
  2014-06-10 15:21       ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-10 11:22 UTC (permalink / raw)
  To: Guruswamy Basavaiah; +Cc: netfilter-devel

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [nftables PATCH] fix nft -i command crashes when try to input multi line command
  2014-06-10 11:22     ` Pablo Neira Ayuso
@ 2014-06-10 15:21       ` Pablo Neira Ayuso
  0 siblings, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-10 15:21 UTC (permalink / raw)
  To: Guruswamy Basavaiah; +Cc: netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]

On Tue, Jun 10, 2014 at 01:22:12PM +0200, Pablo Neira Ayuso wrote:
> 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.

In that direction, I took your patch and included that change into it.
Find it attached. If nobody rise the hand, I'll push it to master.

[-- Attachment #2: 0001-cli-fix-nft-i-command-crashes-when-try-to-input-mult.patch --]
[-- Type: text/x-diff, Size: 1694 bytes --]

>From b24ac2bfe6b6e4b0c1a5ac164369aafc61b75ed9 Mon Sep 17 00:00:00 2001
From: Guruswamy Basavaiah <guru2018@gmail.com>
Date: Sun, 8 Jun 2014 00:44:16 +0530
Subject: [PATCH] cli: fix nft -i command crashes when try to input multi line
 command

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>

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

diff --git a/src/cli.c b/src/cli.c
index 8875207..f748a0e 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,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;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-10 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-07 19:14 [nftables PATCH] fix nft -i command crashes when try to input multi line command Guruswamy B
2014-06-10 10:55 ` Pablo Neira Ayuso
2014-06-10 11:05   ` Guruswamy Basavaiah
2014-06-10 11:22     ` Pablo Neira Ayuso
2014-06-10 15:21       ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).