From: Chen Gang <gang.chen@asianux.com>
To: pablo@netfilter.org, kaber@trash.net, kuznet@ms2.inr.ac.ru,
jmorris@namei.org, yoshfuji@linux-ipv6.org
Cc: David Miller <davem@davemloft.net>,
netfilter-devel@vger.kernel.org, netfilter@vger.kernel.org,
coreteam@netfilter.org, netdev <netdev@vger.kernel.org>
Subject: [PATCH] ipv4: netfilter: always let NUL terminated string ended by '\0'
Date: Fri, 17 May 2013 16:39:15 +0800 [thread overview]
Message-ID: <5195ECB3.5000006@asianux.com> (raw)
For NUL terminated string, better always be sure of ended by '\0'.
'pm' is 'struct ulog_packet_msg_t' which may be copied to user mode
(defined in "include/uapi/..."), so can not use strlcpy() instead of.
Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
net/ipv4/netfilter/ipt_ULOG.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index f8a222cb..4a93382 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -231,11 +231,13 @@ static void ipt_ulog_packet(unsigned int hooknum,
put_unaligned(tv.tv_usec, &pm->timestamp_usec);
put_unaligned(skb->mark, &pm->mark);
pm->hook = hooknum;
- if (prefix != NULL)
- strncpy(pm->prefix, prefix, sizeof(pm->prefix));
- else if (loginfo->prefix[0] != '\0')
- strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
- else
+ if (prefix != NULL) {
+ strncpy(pm->prefix, prefix, sizeof(pm->prefix) - 1);
+ pm->prefix[sizeof(pm->prefix) - 1] = '\0';
+ } else if (loginfo->prefix[0] != '\0') {
+ strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix) - 1);
+ pm->prefix[sizeof(pm->prefix) - 1] = '\0';
+ } else
*(pm->prefix) = '\0';
if (in && in->hard_header_len > 0 &&
@@ -246,14 +248,17 @@ static void ipt_ulog_packet(unsigned int hooknum,
} else
pm->mac_len = 0;
- if (in)
- strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
- else
+ if (in) {
+ strncpy(pm->indev_name, in->name, sizeof(pm->indev_name) - 1);
+ pm->indev_name[sizeof(pm->indev_name) - 1] = '\0';
+ } else
pm->indev_name[0] = '\0';
- if (out)
- strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
- else
+ if (out) {
+ strncpy(pm->outdev_name, out->name,
+ sizeof(pm->outdev_name) - 1);
+ pm->outdev_name[sizeof(pm->outdev_name) - 1] = '\0';
+ } else
pm->outdev_name[0] = '\0';
/* copy_len <= skb->len, so can't fail. */
--
1.7.7.6
next reply other threads:[~2013-05-17 8:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-17 8:39 Chen Gang [this message]
2013-05-23 11:08 ` [PATCH] ipv4: netfilter: always let NUL terminated string ended by '\0' Pablo Neira Ayuso
2013-05-23 11:39 ` Chen Gang
2013-05-23 11:49 ` Pablo Neira Ayuso
2013-05-23 11:49 ` Pablo Neira Ayuso
2013-05-23 11:59 ` Chen Gang
2013-05-23 11:50 ` [PATCH v2] " Chen Gang
2013-05-23 12:26 ` Pablo Neira Ayuso
2013-05-24 1:11 ` Chen Gang
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=5195ECB3.5000006@asianux.com \
--to=gang.chen@asianux.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=jmorris@namei.org \
--cc=kaber@trash.net \
--cc=kuznet@ms2.inr.ac.ru \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=netfilter@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=yoshfuji@linux-ipv6.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.