From patchwork Fri Jul 14 12:07:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 107799 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp894797obm; Fri, 14 Jul 2017 05:15:13 -0700 (PDT) X-Received: by 10.84.231.207 with SMTP id g15mr16069228pln.146.1500034512978; Fri, 14 Jul 2017 05:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500034512; cv=none; d=google.com; s=arc-20160816; b=ZAEfbBdlDq99db4cwNmInOvh5yG087cpXlo0446vVOJKEAc+dGvcjg85EIxDkdw+mE SCERT68zuYMlVoSc2lfVsdtWKyf7D8uFuS1GvBUM9TDryNn8DWivZWSq3lG0hlHhjccq QoODYmD1auV3kVFDR8A2wiMf1FD3UwqRF4rXrqLQrhBV5GI9/4qtmkWKmP3cUoKJWIY4 QoDUKZLJQPk4Z/JDRDVqebsI4uBRB0HBCKstXh3H/aNsojCAlRqoQye5I/b3A/29g2L2 2aAZ2cIaN1AFCsDmS+T/2TdjfSsWUly3Y7gjE8VSCsyLTKfRJf6YhLEjrUxJbTSIC9BP WDSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=awXEF2Uu1wMi80lL+C3ViWbyuJAZNZUUVCr/AAJFgzA=; b=EnMrB3GH5nUuysLU56I26ptt382DttaX3XS2A1dpsxdrxGwwiWP32yJ85FpQSsghZT wkUtaSbsSxVoV1Yn50+wBAlfdIhyJu2HAmmYoAGkV60b624+IvusbObxoAtSKC9radUb dUbjNs3XyTRxC5ZGxJTZlVhl17KzrP5arK47ju/GQTSFCvWLUaOBhTZI7dzJuUOQMq5H FQz39s8R0CrBtNIpSaZOkbM4AfCaUepClT5ZZLNXWohAQj6IeixFAXF6WyHxaE+vTTSK 3oI99mZpqBCugpTM1Z4y7PmTP9yA+Jl34pAm1IrwcnswxesInd8Zyzp8vDSvGyxLn2jl DIrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i14si6123201pgn.378.2017.07.14.05.15.12; Fri, 14 Jul 2017 05:15:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932288AbdGNMPF (ORCPT + 25 others); Fri, 14 Jul 2017 08:15:05 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:63997 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932096AbdGNMPB (ORCPT ); Fri, 14 Jul 2017 08:15:01 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0LmL6w-1e5bT81NHG-00a0EH; Fri, 14 Jul 2017 14:13:12 +0200 From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Jaroslav Kysela , Takashi Iwai Cc: Greg Kroah-Hartman , Linus Torvalds , Guenter Roeck , akpm@linux-foundation.org, netdev@vger.kernel.org, "David S . Miller" , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, x86@kernel.org, Arnd Bergmann , Geliang Tang , Takashi Sakamoto , alsa-devel@alsa-project.org Subject: [PATCH 20/22] sound: pci: avoid string overflow warnings Date: Fri, 14 Jul 2017 14:07:12 +0200 Message-Id: <20170714120720.906842-21-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170714120720.906842-1-arnd@arndb.de> References: <20170714120720.906842-1-arnd@arndb.de> X-Provags-ID: V03:K0:2a1qiNGsbAz+JEP9EFtVZDTtmPufZMk4TbnjrydLFs5DBmyzI++ tVSQVWwC1ihUgzcq+rp0h/2jLP08DGUN0u0mKtIyAHHmi/Xzmo+w9/7kGFBC12JT9ugaZmF b++HUv1eT11pmrh9yqmF1qpI8XpEQLOrWSTqqhmRZ9kLTUFfcbUUvPiF+f1yLKWgWfxwFja mV0zuljx9d4h3kzL5uyFA== X-UI-Out-Filterresults: notjunk:1; V01:K0:jfugXBTu1WQ=:uNxZb6LTb+ztV3hUL9OUI1 /35GBaaaqtA+sENUWG/ZEksLAlJnBME83K22IiZdFLCh/jfFx/omBhOFqwEauiXO0DPG0+0xa zG4jNkhW13cNPQPM8l9XU0lwbY6f/q3gu8lVmBgBMDz9HyAoBCwLO8z+owvXppuoAAQKddZmY NrHpBoYO4HR7zdig9AIH6rdmsfCiXuFI6Et4r+pk+P1x8FE0tRvsFWorX+Ojr4BQaKVys2EYz Y4fersyf0Ho23KoQumnc+Jwv5KKhT2L7z4ZSojhC+F5Xay0Ic1SsidkSNvbhvpAT97WHebrze Ls8MG2zqfecnVd70dkTvupmEgl0AuTz0kLsRztyMhuEzgifGvA0TwM7HZim3Pbe+NZzFdZ447 +gRfxY4DGLvo5R3IIXslcKb0F0T7/oHdlWtyeDf5rg6g7HTTXFAL7W/OWnaXp0Y/sNA1CJIYI SiR9e0/2Gj3DpaHnsVipj4aVrmHSJE3gNmAvMLQOeBs3gZxD27X143IAKFZFfMGvqVPppNESP RPeBQ4T1RhNZcScybwnC8fvK35vzNaJkivM7DcxUPHrZbPwIJzLAlIWSu3yFB121JnoLNZQx2 8RdJ8FONuqLPN5bnrnXcvnEe3z4h29j7ZcsaDJTTUDocvqo+wm2mik3oy8rWOn/J7TRQMWerO j9kiHEGy4l0AU/fZXPEIr+pTnZGq1HJvwaIH6Bz8yMAi3d2KNAt3aBqE+/1R9U3N8NWaTlsHm q8S+1+vTHE+0RpJwcAtcpKmzf6sjcYYdbW3aaw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With gcc-7, we get various warnings about a possible string overflow: sound/pci/rme9652/hdspm.c: In function 'snd_hdspm_create_alsa_devices': sound/pci/rme9652/hdspm.c:2123:17: error: ' MIDIoverMADI' directive writing 13 bytes into a region of size between 1 and 32 [-Werror=format-overflow=] sound/pci/pcxhr/pcxhr.c: In function 'pcxhr_probe': sound/pci/pcxhr/pcxhr.c:1647:28: error: ' [PCM #' directive writing 7 bytes into a region of size between 1 and 32 [-Werror=format-overflow=] sound/pci/mixart/mixart.c: In function 'snd_mixart_probe': sound/pci/mixart/mixart.c:1353:28: error: ' [PCM #' directive writing 7 bytes into a region of size between 1 and 32 [-Werror=format-overflow=] sprintf(card->shortname, "%s [PCM #%d]", mgr->shortname, i); ^~~~~~~~~~~~~~ sound/pci/mixart/mixart.c:1353:28: note: using the range [-2147483648, 2147483647] for directive argument sound/pci/mixart/mixart.c:1353:3: note: 'sprintf' output between 10 and 51 bytes into a destination of size 32 sprintf(card->shortname, "%s [PCM #%d]", mgr->shortname, i); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sound/pci/mixart/mixart.c:1354:27: error: ' [PCM #' directive writing 7 bytes into a region of size between 1 and 80 [-Werror=format-overflow=] sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i); ^~~~~~~~~~~~~~ sound/pci/mixart/mixart.c:1354:27: note: using the range [-2147483648, 2147483647] for directive argument sound/pci/mixart/mixart.c:1354:3: note: 'sprintf' output between 10 and 99 bytes into a destination of size 80 I have checked these all and found that the driver-private shortname strings for mixart and pcxhr are longer than necessary, and making them shorter will be safe while also making it clear that no overflow can happen when they get passed as a substring into the card shortname. For hdspm, we have a local buffer of the same size as its substring. In this case, making the buffer a little longer is safe as the functions that take it as an argument all use length checking and the strings we pass into it are actually short enough. Signed-off-by: Arnd Bergmann --- sound/pci/mixart/mixart.h | 4 ++-- sound/pci/pcxhr/pcxhr.h | 4 ++-- sound/pci/rme9652/hdspm.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) -- 2.9.0 diff --git a/sound/pci/mixart/mixart.h b/sound/pci/mixart/mixart.h index 426743871540..c8309e327663 100644 --- a/sound/pci/mixart/mixart.h +++ b/sound/pci/mixart/mixart.h @@ -75,8 +75,8 @@ struct mixart_mgr { struct mem_area mem[2]; /* share the name */ - char shortname[32]; /* short name of this soundcard */ - char longname[80]; /* name of this soundcard */ + char shortname[16]; /* short name of this soundcard */ + char longname[40]; /* name of this soundcard */ /* one and only blocking message or notification may be pending */ u32 pending_event; diff --git a/sound/pci/pcxhr/pcxhr.h b/sound/pci/pcxhr/pcxhr.h index 9e39e509a3ef..4909a43ce3d9 100644 --- a/sound/pci/pcxhr/pcxhr.h +++ b/sound/pci/pcxhr/pcxhr.h @@ -75,8 +75,8 @@ struct pcxhr_mgr { unsigned long port[3]; /* share the name */ - char shortname[32]; /* short name of this soundcard */ - char longname[96]; /* name of this soundcard */ + char shortname[16]; /* short name of this soundcard */ + char longname[40]; /* name of this soundcard */ struct pcxhr_rmh *prmh; diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 254c3d040118..a1cbf5938a0e 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -2061,7 +2061,7 @@ static int snd_hdspm_create_midi(struct snd_card *card, struct hdspm *hdspm, int id) { int err; - char buf[32]; + char buf[64]; hdspm->midi[id].id = id; hdspm->midi[id].hdspm = hdspm;