From patchwork Tue Mar 19 12:27:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masatake YAMATO X-Patchwork-Id: 229152 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8BEA02C00A3 for ; Wed, 20 Mar 2013 04:28:51 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933153Ab3CSR2e (ORCPT ); Tue, 19 Mar 2013 13:28:34 -0400 Received: from h219-110-095-248.catv01.itscom.jp ([219.110.95.248]:55726 "EHLO localhost.localdomain" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932483Ab3CSR2c (ORCPT ); Tue, 19 Mar 2013 13:28:32 -0400 X-Greylist: delayed 599 seconds by postgrey-1.27 at vger.kernel.org; Tue, 19 Mar 2013 13:28:31 EDT Received: from localhost.localdomain (localhost [127.0.0.1]) by localhost.localdomain (8.14.5/8.14.5) with ESMTP id r2JCRFmx012593; Tue, 19 Mar 2013 21:27:15 +0900 Received: (from yamato@localhost) by localhost.localdomain (8.14.5/8.14.5/Submit) id r2JCRENa012592; Tue, 19 Mar 2013 21:27:14 +0900 X-Authentication-Warning: localhost.localdomain: yamato set sender to yamato@redhat.com using -f From: Masatake YAMATO To: netdev@vger.kernel.org Cc: Masatake YAMATO Subject: [PATCH] Truncate MCAST_GRP_NAME and FAMILY_NAME char arrays as C strings Date: Tue, 19 Mar 2013 21:27:09 +0900 Message-Id: <1363696029-12559-1-git-send-email-yamato@redhat.com> X-Mailer: git-send-email 1.7.11.7 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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]) {