From: Florian Westphal <fw@strlen.de>
To: Phil Oester <kernel@linuxace.com>
Cc: netfilter-devel@vger.kernel.org, pablo@netfilter.org
Subject: Re: [PATCH] iptables: set errno correctly in iptcc_chain_index_alloc
Date: Thu, 4 Jul 2013 09:42:22 +0200 [thread overview]
Message-ID: <20130704074222.GC2351@breakpoint.cc> (raw)
In-Reply-To: <20130704011610.GA9791@linuxace.com>
Phil Oester <kernel@linuxace.com> wrote:
> As reported by Robert Barnhardt, iptcc_chain_index_alloc does not populate
> errno with the appropriate ENOMEM on allocation failures. This causes
> incorrect error messages to be passed back to user such as "can't initialize
> iptables table 'X'" even if the issue was caused by OOM condition. Fix
> this by passing back ENOMEM if allocation failure occurs.
Personally I think libraries should not change errno at all.
> diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
> index f0f7815..004b0ec 100644
> --- a/libiptc/libiptc.c
> +++ b/libiptc/libiptc.c
> @@ -502,7 +502,8 @@ static int iptcc_chain_index_alloc(struct xtc_handle *h)
> h->chain_index = malloc(array_mem);
> if (h->chain_index == NULL && array_mem > 0) {
> h->chain_index_sz = 0;
> - return -ENOMEM;
> + errno = ENOMEM;
> + return -1;
> }
I don't understand how this changes anything?
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) { errno = EINVAL;
void *v = malloc(0xffffffffffffffff);
if (v == 0) perror("malloc"); }
Yields "Cannot allocate memory", not "Invalid argument".
next prev parent reply other threads:[~2013-07-04 7:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-04 1:16 [PATCH] iptables: set errno correctly in iptcc_chain_index_alloc Phil Oester
2013-07-04 7:42 ` Florian Westphal [this message]
2013-07-04 16:18 ` Phil Oester
2013-07-04 16:33 ` Florian Westphal
2013-07-04 16:52 ` Phil Oester
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=20130704074222.GC2351@breakpoint.cc \
--to=fw@strlen.de \
--cc=kernel@linuxace.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).