From: Masatake YAMATO <yamato@redhat.com>
To: netdev@vger.kernel.org
Cc: Masatake YAMATO <yamato@redhat.com>
Subject: [PATCH] Truncate MCAST_GRP_NAME and FAMILY_NAME char arrays as C strings
Date: Tue, 19 Mar 2013 21:27:09 +0900 [thread overview]
Message-ID: <1363696029-12559-1-git-send-email-yamato@redhat.com> (raw)
This is a patch for genl command in iproute2.
You will see garbage at the end of line in the output of following command line:
$ genl ctrl show | grep thermal_mc_group
#1: ID-0x2 name: thermal_mc_group^B
The type of structure field for "name" is char[16] in kernel:
#define GENL_NAMSIZ 16 /* length of family name */
...
struct genl_multicast_group {
...
char name[GENL_NAMSIZ];
...
};
strlen("thermal_mc_group") == 16 is too long for the array size.
This patch protects genl process from this kind of bug by putting
nul char at the end of array after receiving a message from the
kernel.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
genl/ctrl.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/genl/ctrl.c b/genl/ctrl.c
index 7c42578..fd5a50a 100644
--- a/genl/ctrl.c
+++ b/genl/ctrl.c
@@ -168,6 +168,7 @@ static int print_ctrl_grp(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
}
if (tb[1]) {
char *name = RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_NAME]);
+ name[GENL_NAMSIZ - 1] = '\0';
fprintf(fp, " name: %s ", name);
}
return 0;
@@ -214,6 +215,7 @@ static int print_ctrl(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (tb[CTRL_ATTR_FAMILY_NAME]) {
char *name = RTA_DATA(tb[CTRL_ATTR_FAMILY_NAME]);
+ name[GENL_NAMSIZ - 1] = '\0';
fprintf(fp, "\nName: %s\n",name);
}
if (tb[CTRL_ATTR_FAMILY_ID]) {
--
1.7.11.7
reply other threads:[~2013-03-19 17:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1363696029-12559-1-git-send-email-yamato@redhat.com \
--to=yamato@redhat.com \
--cc=netdev@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).