netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Eric Leblond <eric@inl.fr>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 6/6] ulogd: use snprintf instead of sprintf in printpkt
Date: Thu, 30 Sep 2010 11:48:50 +0200	[thread overview]
Message-ID: <4CA45D02.8040702@netfilter.org> (raw)
In-Reply-To: <1285116442-32490-7-git-send-email-eric@inl.fr>

Hi Eric,

On 22/09/10 02:47, Eric Leblond wrote:
> diff --git a/util/printpkt.c b/util/printpkt.c
> index 5250792..a800555 100644
> --- a/util/printpkt.c
> +++ b/util/printpkt.c
> @@ -106,91 +106,93 @@ struct ulogd_key printpkt_keys[] = {
>  	[KEY_SCTP_DPORT]	= { .name = "sctp.dport", },
>  };
>  
> -static int printpkt_proto(struct ulogd_key *res, char *buf, int protocol)
> +static int printpkt_proto(struct ulogd_key *res, char *buf, size_t bufsiz, int protocol)
>  {
>  	char *buf_cur = buf;
> +	char *end_buf = buf + bufsiz;
> +
>  
>  	switch (protocol) {
>  	case IPPROTO_TCP:
> -		buf_cur += sprintf(buf_cur, "PROTO=TCP ");
> +		buf_cur += snprintf(buf_cur, bufsiz, "PROTO=TCP ");

If you have to fix this. snprintf can return -1 in case of error.
Moreover, it returns the number of bytes that would have been written if
there's space in the buffer. So you have to check if the return value is
higher that the remaining space in the buffer.

Have a look at the use of snprintf in libnetfilter_queue and
libnetfilter_log in nf*snprintf_xml() function for instance.

      reply	other threads:[~2010-09-30  9:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-22  0:47 [ULOGD PATCH 0/6] misc improvements and code cleaning Eric Leblond
2010-09-22  0:47 ` [PATCH 1/6] build: nfct and nflog can be disabled via configure option Eric Leblond
2010-09-30  9:58   ` Pablo Neira Ayuso
2010-09-22  0:47 ` [PATCH 2/6] ulogd.conf: Comment library dependant plugins Eric Leblond
2010-09-30  9:51   ` Pablo Neira Ayuso
2010-09-30 21:23     ` Eric Leblond
2010-09-22  0:47 ` [PATCH 3/6] build: add debug configure flag Eric Leblond
2010-09-30  9:50   ` Pablo Neira Ayuso
2010-09-30 21:22     ` Eric Leblond
2010-10-01 22:22       ` Jan Engelhardt
2010-10-03 10:15         ` Pablo Neira Ayuso
2010-09-22  0:47 ` [PATCH 4/6] ulogd.conf: add a complex but useful stack example Eric Leblond
2010-09-22  0:47 ` [PATCH 5/6] filter_MARK: code factorization Eric Leblond
2010-09-22  0:47 ` [PATCH 6/6] ulogd: use snprintf instead of sprintf in printpkt Eric Leblond
2010-09-30  9:48   ` 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=4CA45D02.8040702@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=eric@inl.fr \
    --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).