From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [libnftnl PATCH 1/2] utils: ensure \0 is in place in nft_fprintf()
Date: Mon, 25 Aug 2014 16:09:08 +0200 [thread overview]
Message-ID: <20140825140908.GA5147@salvia> (raw)
In-Reply-To: <20140825130221.23329.86583.stgit@nfdev.cica.es>
On Mon, Aug 25, 2014 at 03:02:21PM +0200, Arturo Borrero Gonzalez wrote:
> We must make sure the buffer contains a \0 in the last position,
> to avoid printing trash by the last fprintf() call.
snprintf already guarantees that the string is nul-terminated if there
is enough room to add \0.
ret = snprintf_cb(buf, bufsiz, obj, type, flags);
if (ret < 0)
goto out;
if (ret >= NFT_SNPRINTF_BUFSIZ) {
bufsiz = ret + 1;
buf = malloc(bufsiz);
if (buf == NULL)
return -1;
ret = snprintf_cb(buf, bufsiz, obj, type, flags);
if (ret < 0)
goto out;
}
ret = fprintf(fp, "%s", buf);
I think we have guarantees that buf is always nul-terminated after the
second try.
Patch 2/2 looks good to enough to me since it already resolves the
printed "garbage" at the end of the output issue.
prev parent reply other threads:[~2014-08-25 14:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-25 13:02 [libnftnl PATCH 1/2] utils: ensure \0 is in place in nft_fprintf() Arturo Borrero Gonzalez
2014-08-25 13:02 ` [libnftnl PATCH 2/2] src: improve printing of XML/JSON event wrapper header/footer Arturo Borrero Gonzalez
2014-08-25 14:12 ` Pablo Neira Ayuso
2014-08-25 14:09 ` Pablo Neira Ayuso [this message]
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=20140825140908.GA5147@salvia \
--to=pablo@netfilter.org \
--cc=arturo.borrero.glez@gmail.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).