From: "mancha" <mancha1@hush.com>
To: netfilter-devel@vger.kernel.org
Subject: ip{,6}tables-save misleading return code
Date: Mon, 14 Oct 2013 20:38:16 +0000 [thread overview]
Message-ID: <20131014203816.CC16360191@smtp.hushmail.com> (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
--- a/iptables/iptables-save.c 2013-10-14
+++ b/iptables/iptables-save.c 2013-10-14
@@ -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')
--- a/iptables/ip6tables-save.c 2013-10-14
+++ b/iptables/ip6tables-save.c 2013-10-14
@@ -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')
next reply other threads:[~2013-10-14 21:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-14 20:38 mancha [this message]
2013-10-17 8:39 ` ip{,6}tables-save misleading return code Pablo Neira Ayuso
2013-10-17 18:10 ` mancha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131014203816.CC16360191@smtp.hushmail.com \
--to=mancha1@hush.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).