linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: linux-kernel@vger.kernel.org,
	Sathya Prakash <sathya.prakash@broadcom.com>,
	Chaitra P B <chaitra.basappa@broadcom.com>,
	Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Guenter Roeck <linux@roeck-us.net>,
	akpm@linux-foundation.org, netdev@vger.kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	linux-scsi@vger.kernel.org, x86@kernel.org,
	Arnd Bergmann <arnd@arndb.de>, Hannes Reinecke <hare@suse.de>,
	Calvin Owens <calvinowens@fb.com>,
	Adam Manzanares <adam.manzanares@wdc.com>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	MPT-FusionLinux.pdl@broadcom.com
Subject: [PATCH 03/22] scsi: mpt3sas: fix format overflow warning
Date: Fri, 14 Jul 2017 14:06:55 +0200	[thread overview]
Message-ID: <20170714120720.906842-4-arnd@arndb.de> (raw)
In-Reply-To: <20170714120720.906842-1-arnd@arndb.de>

We print the driver name into one string and then add and ID
and copy it into a second string of the same length, at which
point gcc complains about a possible overflow:

drivers/scsi/mpt3sas/mpt3sas_scsih.c: In function '_scsih_probe':
drivers/scsi/mpt3sas/mpt3sas_scsih.c:8884:21: error: '_cm' directive writing 3 bytes into a region of size between 1 and 32 [-Werror=format-overflow=]
printf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
                  ^~~~~~~~~
drivers/scsi/mpt3sas/mpt3sas_scsih.c:8884:21: note: directive argument in the range [0, 255]
drivers/scsi/mpt3sas/mpt3sas_scsih.c:8884:2: note: 'sprintf' output between 5 and 38 bytes into a destination of size 32
  sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Making the first string shorter is sufficient to avoid the
warning here, as we know it can only contain either "mpt2sas"
or "mpt3sas".

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/scsi/mpt3sas/mpt3sas_base.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 099ab4ca7edf..a77bb7dc12b1 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -970,7 +970,7 @@ struct MPT3SAS_ADAPTER {
 	u8		id;
 	int		cpu_count;
 	char		name[MPT_NAME_LENGTH];
-	char		driver_name[MPT_NAME_LENGTH];
+	char		driver_name[MPT_NAME_LENGTH - 8];
 	char		tmp_string[MPT_STRING_LENGTH];
 	struct pci_dev	*pdev;
 	Mpi2SystemInterfaceRegs_t __iomem *chip;
-- 
2.9.0

  parent reply	other threads:[~2017-07-14 12:06 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14 12:06 [PATCH 00/22] gcc-7 -Wformat-* warnings Arnd Bergmann
2017-07-14 12:06 ` [PATCH 01/22] kbuild: disable -Wformat-truncation warnings by default Arnd Bergmann
2017-07-14 12:06 ` [PATCH 02/22] scsi: megaraid: fix format-overflow warning Arnd Bergmann
2017-07-14 12:06 ` Arnd Bergmann [this message]
2017-07-14 12:06 ` [PATCH 04/22] scsi: fusion: fix string overflow warning Arnd Bergmann
2017-07-17  9:17   ` David Laight
2017-07-17 12:00     ` Arnd Bergmann
2017-07-14 12:06 ` [PATCH 05/22] scsi: gdth: avoid buffer " Arnd Bergmann
2017-07-14 12:06 ` [PATCH 06/22] scsi: fnic: fix format string " Arnd Bergmann
2017-07-14 12:06 ` [PATCH 07/22] scsi: gdth: increase the procfs event buffer size Arnd Bergmann
2017-07-14 12:07 ` [PATCH 08/22] isdn: divert: fix sprintf buffer overflow warning Arnd Bergmann
2017-07-14 16:03   ` David Miller
2017-07-14 12:07 ` [PATCH 09/22] net: niu: fix format string overflow warning: Arnd Bergmann
2017-07-14 16:03   ` David Miller
2017-07-14 12:07 ` [PATCH 10/22] bnx2x: fix format overflow warning Arnd Bergmann
2017-07-14 16:03   ` David Miller
2017-07-14 12:07 ` [PATCH 11/22] net: thunder_bgx: avoid format string " Arnd Bergmann
2017-07-14 12:33   ` Robin Murphy
2017-07-14 16:03   ` David Miller
2017-07-14 12:07 ` [PATCH 12/22] vmxnet3: avoid format strint " Arnd Bergmann
2017-07-14 16:04   ` David Miller
2017-07-14 12:07 ` [PATCH 13/22] liquidio: fix possible eeprom format string overflow Arnd Bergmann
2017-07-14 16:04   ` David Miller
2017-07-14 22:40     ` Burla, Satananda
2017-07-14 12:07 ` [PATCH 14/22] [media] usbvision-i2c: fix format overflow warning Arnd Bergmann
2017-07-17 12:53   ` Hans Verkuil
2017-07-17 12:57     ` Arnd Bergmann
2017-07-17 12:59       ` Hans Verkuil
2017-07-14 12:07 ` [PATCH 15/22] hwmon: applesmc: fix format string overflow Arnd Bergmann
2017-07-14 14:06   ` Guenter Roeck
2017-07-14 12:07 ` [PATCH 16/22] x86: intel-mid: fix a format string overflow warning Arnd Bergmann
2017-07-14 12:07 ` [PATCH 17/22] platform/x86: alienware-wmi: fix " Arnd Bergmann
2017-07-14 18:30   ` Mario.Limonciello
2017-07-14 19:18   ` Andy Shevchenko
2017-07-14 19:37     ` Arnd Bergmann
2017-07-14 19:49       ` Andy Shevchenko
2017-07-14 12:07 ` [PATCH 18/22] gpio: acpi: fix string overflow for large pin numbers Arnd Bergmann
2017-07-14 12:52   ` Andy Shevchenko
2017-07-14 19:59     ` Arnd Bergmann
2017-07-14 12:07 ` [PATCH 19/22] block: DAC960: shut up format-overflow warning Arnd Bergmann
2017-07-14 14:04   ` Jens Axboe
2017-07-14 12:07 ` [PATCH 20/22] sound: pci: avoid string overflow warnings Arnd Bergmann
2017-07-14 12:28   ` Takashi Iwai
2017-07-18 11:52     ` Arnd Bergmann
2017-07-14 12:07 ` [PATCH 21/22] fscache: fix fscache_objlist_show format processing Arnd Bergmann
2017-07-14 12:07 ` [PATCH 22/22] IB/mlx4: fix sprintf format warning Arnd Bergmann
2017-07-14 13:48   ` Leon Romanovsky
2017-07-25  1:48 ` [PATCH 00/22] gcc-7 -Wformat-* warnings Martin K. Petersen

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=20170714120720.906842-4-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=MPT-FusionLinux.pdl@broadcom.com \
    --cc=adam.manzanares@wdc.com \
    --cc=akpm@linux-foundation.org \
    --cc=bart.vanassche@sandisk.com \
    --cc=calvinowens@fb.com \
    --cc=chaitra.basappa@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=hare@suse.de \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=martin.petersen@oracle.com \
    --cc=netdev@vger.kernel.org \
    --cc=sathya.prakash@broadcom.com \
    --cc=suganath-prabu.subramani@broadcom.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@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).