From patchwork Mon Sep 15 02:05:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 389176 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 04CD01400D6 for ; Mon, 15 Sep 2014 12:06:30 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752500AbaIOCGD (ORCPT ); Sun, 14 Sep 2014 22:06:03 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:62773 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752512AbaIOCGB (ORCPT ); Sun, 14 Sep 2014 22:06:01 -0400 Received: by mail-pd0-f172.google.com with SMTP id v10so5168343pde.17 for ; Sun, 14 Sep 2014 19:06:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=U9ZA98emJsW7+/0dkH+7siMtKXanLI5VIoBA4OQ1nrU=; b=AkJJJsqjpYCeXEGuzwlln8ZgJBfeUBpzNiiqEzNC1rRjDR+YoKpuqvLuZ7iSqAgoBp kYj/m/iR8WYQuYTfJu9TV6qhMCPNtIhq0LeiiOPa2zJg1TqzuhNERg3cG4uF5voF9DsW F+GZnMMaxgLCykiuvOID5yK4jWLnNVSsfkA7ElgDlKNHDqpf+XvLXwvDNczgqrIVE5U3 dbHIbCH5imktvjoxiB0EnirdFuNlGLdzkrDvPPaFC27scpqxIYpNe4FRG9lo5DIP4Y+A L317Kd6a/WOCvOf4OYwaQpweLry8Bq0xhSl7VFQTsI5ynRrxsh7XBZyUF4DRpn5RINtA wKOw== X-Gm-Message-State: ALoCoQkNyYqi/pfpm9zD86fSRluZd3WQ6u931+QQWSPs9ksjQeHgDDFas019gQFVqdsNQMbn6/EZ X-Received: by 10.66.191.230 with SMTP id hb6mr34004642pac.72.1410746760284; Sun, 14 Sep 2014 19:06:00 -0700 (PDT) Received: from urahara (static-50-53-65-80.bvtn.or.frontiernet.net. [50.53.65.80]) by mx.google.com with ESMTPSA id zf5sm9808205pbc.44.2014.09.14.19.05.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Sep 2014 19:05:59 -0700 (PDT) Date: Sun, 14 Sep 2014 19:05:57 -0700 From: Stephen Hemminger To: Rickard Strandqvist Cc: Mirko Lindner , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: ethernet: marvell: sky2.c: Cleaning up missing null-terminate in conjunction with strncpy Message-ID: <20140914190557.690183d2@urahara> In-Reply-To: <1410716023-16068-1-git-send-email-rickard_strandqvist@spectrumdigital.se> References: <1410716023-16068-1-git-send-email-rickard_strandqvist@spectrumdigital.se> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sun, 14 Sep 2014 19:33:43 +0200 Rickard Strandqvist wrote: > Replacing strncpy with strlcpy to avoid strings that lacks null terminate. > > Signed-off-by: Rickard Strandqvist > --- > drivers/net/ethernet/marvell/sky2.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c > index dba48a5c..7053d38 100644 > --- a/drivers/net/ethernet/marvell/sky2.c > +++ b/drivers/net/ethernet/marvell/sky2.c > @@ -4907,7 +4907,7 @@ static const char *sky2_name(u8 chipid, char *buf, int sz) > }; > > if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2) > - strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz); > + strlcpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz); > else > snprintf(buf, sz, "(chip %#x)", chipid); > return buf; Useless and unnecessary since the list of names is right there. Why not avoid the copy all together? Subject: sky2: avoid strncpy Don't use strncpy() since security thought police think it is bad. Signed-off-by: Stephen Hemminger --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/net/ethernet/marvell/sky2.c 2014-08-25 09:01:16.292060455 -0700 +++ b/drivers/net/ethernet/marvell/sky2.c 2014-09-14 19:02:26.731034094 -0700 @@ -4889,7 +4889,7 @@ static int sky2_test_msi(struct sky2_hw } /* This driver supports yukon2 chipset only */ -static const char *sky2_name(u8 chipid, char *buf, int sz) +static const char *sky2_name(u8 chipid) { const char *name[] = { "XL", /* 0xb3 */ @@ -4905,11 +4905,12 @@ static const char *sky2_name(u8 chipid, "OptimaEEE", /* 0xbd */ "Optima 2", /* 0xbe */ }; + static char buf[16]; if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2) - strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz); - else - snprintf(buf, sz, "(chip %#x)", chipid); + return name[chipid - CHIP_ID_YUKON_XL]; + + snprintf(buf, sizeof(buf), "(chip %#x)", chipid); return buf; } @@ -4919,7 +4920,6 @@ static int sky2_probe(struct pci_dev *pd struct sky2_hw *hw; int err, using_dac = 0, wol_default; u32 reg; - char buf1[16]; err = pci_enable_device(pdev); if (err) { @@ -5014,7 +5014,7 @@ static int sky2_probe(struct pci_dev *pd } dev_info(&pdev->dev, "Yukon-2 %s chip revision %d\n", - sky2_name(hw->chip_id, buf1, sizeof(buf1)), hw->chip_rev); + sky2_name(hw->chip_id), hw->chip_rev); sky2_reset(hw);