netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org
Subject: [libnftnl PATCH] common: events: be more strict when placing the \0 character
Date: Mon, 14 Jul 2014 14:43:35 +0200	[thread overview]
Message-ID: <20140714124335.13205.77982.stgit@nfdev.cica.es> (raw)

Previous to this patch, the code path can potentially print an empty
buffer with the \0 at the end of the buffer.

Be more strict and place the \0 character in the first position if the
buffer is empty.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 src/common.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/common.c b/src/common.c
index 1b600f1..c81a1d8 100644
--- a/src/common.c
+++ b/src/common.c
@@ -114,9 +114,10 @@ int nft_event_header_snprintf(char *buf, size_t size, uint32_t type,
 int nft_event_header_fprintf(FILE *fp, uint32_t type, uint32_t flags)
 {
 	char buf[64]; /* enough for the maximum string length above */
+	int ret;
 
-	nft_event_header_snprintf(buf, sizeof(buf), type, flags);
-	buf[sizeof(buf) - 1] = '\0';
+	ret = nft_event_header_snprintf(buf, sizeof(buf), type, flags);
+	buf[ret] = '\0';
 
 	return fprintf(fp, "%s", buf);
 }
@@ -140,9 +141,10 @@ int nft_event_footer_snprintf(char *buf, size_t size, uint32_t type,
 int nft_event_footer_fprintf(FILE *fp, uint32_t type, uint32_t flags)
 {
 	char buf[32]; /* enough for the maximum string length above */
+	int ret;
 
-	nft_event_footer_snprintf(buf, sizeof(buf), type, flags);
-	buf[sizeof(buf) - 1] = '\0';
+	ret = nft_event_footer_snprintf(buf, sizeof(buf), type, flags);
+	buf[ret] = '\0';
 
 	return fprintf(fp, "%s", buf);
 }


             reply	other threads:[~2014-07-14 12:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-14 12:43 Arturo Borrero Gonzalez [this message]
2014-07-15 16:42 ` [libnftnl PATCH] common: events: be more strict when placing the \0 character Pablo Neira Ayuso
2014-07-17  8:16   ` Arturo Borrero Gonzalez

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=20140714124335.13205.77982.stgit@nfdev.cica.es \
    --to=arturo.borrero.glez@gmail.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).