From patchwork Fri Mar 8 03:19:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 226020 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 B0DB02C0376 for ; Fri, 8 Mar 2013 14:20:03 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933607Ab3CHDT7 (ORCPT ); Thu, 7 Mar 2013 22:19:59 -0500 Received: from intranet.asianux.com ([58.214.24.6]:25458 "EHLO intranet.asianux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759217Ab3CHDT6 (ORCPT ); Thu, 7 Mar 2013 22:19:58 -0500 Received: by intranet.asianux.com (Postfix, from userid 103) id D1B7F1840256; Fri, 8 Mar 2013 11:19:56 +0800 (CST) X-Spam-Score: -100.8 X-Spam-Checker-Version: SpamAssassin 3.1.9 (2007-02-13) on intranet.asianux.com X-Spam-Level: X-Spam-Status: No, score=-100.8 required=5.0 tests=AWL,BAYES_00, RATWARE_GECKO_BUILD, TW_CP, USER_IN_WHITELIST autolearn=no version=3.1.9 Received: from [10.1.0.143] (unknown [219.143.36.82]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by intranet.asianux.com (Postfix) with ESMTP id 4E35D1840256; Fri, 8 Mar 2013 11:19:54 +0800 (CST) Message-ID: <513958C4.1020404@asianux.com> Date: Fri, 08 Mar 2013 11:19:32 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Ben Hutchings CC: David Laight , venkat.x.venkatsubra@oracle.com, David Miller , rds-devel@oss.oracle.com, netdev Subject: [PATCH] net/rds: zero last byte for strncpy References: <512F1534.9020404@asianux.com> <1362421944.2956.15.camel@bwh-desktop.uk.solarflarecom.com> <1362422090.2956.18.camel@bwh-desktop.uk.solarflarecom.com> <51355936.3060307@asianux.com> <1362453419.3768.380.camel@deadeye.wl.decadent.org.uk> <51356735.4020405@asianux.com> <1362454672.3768.383.camel@deadeye.wl.decadent.org.uk> <51356FED.4070909@asianux.com> <1362502844.2791.32.camel@bwh-desktop.uk.solarflarecom.com> In-Reply-To: <1362502844.2791.32.camel@bwh-desktop.uk.solarflarecom.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org for NUL terminated string, need be always sure '\0' in the end. additional info: strncpy will pads with zeroes to the end of the given buffer. should initialise every bit of memory that is going to be copied to userland Signed-off-by: Chen Gang Signed-off-by: Ben Hutchings --- net/rds/stats.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/net/rds/stats.c b/net/rds/stats.c index 7be790d..73be187 100644 --- a/net/rds/stats.c +++ b/net/rds/stats.c @@ -87,6 +87,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter, for (i = 0; i < nr; i++) { BUG_ON(strlen(names[i]) >= sizeof(ctr.name)); strncpy(ctr.name, names[i], sizeof(ctr.name) - 1); + ctr.name[sizeof(ctr.name) - 1] = '\0'; ctr.value = values[i]; rds_info_copy(iter, &ctr, sizeof(ctr));