Skip to contentSkip to conversation

ip{,6}tables-save misleading return code

PATCH mancha 2 participants 3 messages Oct 14, 2013 – Oct 17, 2013 netfilter

lore
Share & tools
lore

mancha

author
#0 lore raw

Hello, this came up on freenode's #netfilter today.

ip{,6}tables-save(8), when run as an unprivileged user (who doesn't have access to /proc/net/ip{,6}_tables_names), displays no output and returns 0 because of a Boolean inversion.

luser@myhost:~$ iptables-save; echo $? 
0

The patch below changes the return to 1 if fopen() fails. Additionally, one could add "if (errno == EACCESS)" conditioned error messages.

--mancha

iptables/iptables-save.c 2013-10-14 +1 -1
@@ -40,7 +40,7 @@ static int for_each_table(int (*func)(co
 
        procfile = fopen("/proc/net/ip_tables_names", "re");
        if (!procfile)
-               return ret;
+               return 0;
 
        while (fgets(tablename, sizeof(tablename), procfile)) {
                if (tablename[strlen(tablename) - 1] != '\n')
iptables/ip6tables-save.c 2013-10-14 +1 -1
@@ -42,7 +42,7 @@ static int for_each_table(int (*func)(co
 
        procfile = fopen("/proc/net/ip6_tables_names", "re");
        if (!procfile)
-               return ret;
+               return 0;
 
        while (fgets(tablename, sizeof(tablename), procfile)) {
                if (tablename[strlen(tablename) - 1] != '\n')
#1 lore raw

Hi,

Quoted 6 lines · mancha

Hello, this came up on freenode's #netfilter today.

ip{,6}tables-save(8), when run as an unprivileged user (who doesn't have access to /proc/net/ip{,6}_tables_names), displays no output and returns 0 because of a Boolean inversion.

Quoted 6 lines
luser@myhost:~$ iptables-save; echo $? 
0

The patch below changes the return to 1 if fopen() fails. Additionally, one could add "if (errno == EACCESS)" conditioned error messages.

Need your Signed-off-by tag / full name to take this patch, please, let me know. No need to resend, I'll amend it. Thanks.

author
#2 lore raw
Quoted 3 lines · Pablo Neira Ayuso <pablo <at> netfilter.org> writes:

Need your Signed-off-by tag / full name to take this patch, please, let me know. No need to resend, I'll amend it. Thanks.

Hi. Thank you for your email.

As for attribution, my Signed-off-by tag is "mancha". I didn't mean to add more work for you. In the future I'll submit using git format-patch.

Thanks!

--mancha