Skip to contentSkip to conversation

xtables-translate: don't fail if help was requested

PATCH In review Arturo Borrero Gonzalez 2 participants 3 messages Jun 16, 2020 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xtables-translate: don't fail if help was requested

If the user called iptables-translate -h then we have CMD_NONE and we should gracefully handle this case in do_command_xlate().

Before this patch, you would see:

 user@debian:~$ sudo iptables-translate -h
 [..]
 nft Unsupported command?
 user@debian:~$ echo $?
 1

After this patch:

 user@debian:~$ sudo iptables-translate -h
 [..]
 user@debian:~$ echo $?
 0
Fixes d4409d449c10fa ("nft: Don't exit early after printing help texts")
---
 iptables/xtables-translate.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
iptables/xtables-translate.c +4 -1
index 5aa42496..363c8be1 100644
@@ -249,7 +249,7 @@ static int do_command_xlate(struct nft_handle *h, int argc, char *argv[],
 
 	cs.restore = restore;
 
-	if (!restore)
+	if (!restore && p.command != CMD_NONE)
 		printf("nft ");
 
 	switch (p.command) {
@@ -310,6 +310,9 @@ static int do_command_xlate(struct nft_handle *h, int argc, char *argv[],
 		break;
 	case CMD_SET_POLICY:
 		break;
+	case CMD_NONE:
+		ret = 1;
+		break;
 	default:
 		/* We should never reach this... */
 		printf("Unsupported command?\n");
reviewer Acked-by on v1 1/1
#1 lore raw

Hi Arturo,

Quoted 11 lines · Arturo Borrero Gonzalez

If the user called iptables-translate -h then we have CMD_NONE and we should gracefully handle this case in do_command_xlate().

Before this patch, you would see:

 user@debian:~$ sudo iptables-translate -h
 [..]
 nft Unsupported command?
 user@debian:~$ echo $?
 1
Quoted 6 lines

After this patch:

 user@debian:~$ sudo iptables-translate -h
 [..]
 user@debian:~$ echo $?
 0

Apparently I forgot to test xtables-restore after changing help functions, thanks for fixing this up.

Quoted 2 lines
Fixes d4409d449c10fa ("nft: Don't exit early after printing help texts")

Thanks, Phil