Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp845156imu; Tue, 11 Dec 2018 08:25:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/X8SB9w8pQ/Natr39GLQ3tliCQhMhlWLMPes0QJfPRLvvBpTAsSV7ws1TgO8YVBsLJhPoSL X-Received: by 2002:a63:9809:: with SMTP id q9mr15145512pgd.109.1544545530624; Tue, 11 Dec 2018 08:25:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544545530; cv=none; d=google.com; s=arc-20160816; b=mlHP130jSoRDkBbxoDySKZ1z75RAskkHx9WBz10ZkSafzzSQ0pZaiIj2kw7+cl5tvp a3uICuO5QwHOBhbS9Y8R75xX4dYi5zpR9mVt1nQ0XW8PvRmpY1CGbtmGpAes6pyJoiMu o359ZoeFtC9+uaKoSd1ty5xHHRV4LnvmmhCh5gRqg1SWAezZyNdL1IA9XXMUw6SbXnN0 SQelgD+WpFrPeKbG+CWn72kjRW+0gvPOpcBWHduUtj9LYw1LUN3i30UXA5hnOp03xEQz ypyIkQyKbjoM5JCYuNl6yO7Fo1fPIxP9jd5QX2k6mGlphmSd79FBYi0vpPy3v6ToeKvt /l4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UeN4KTZcrAwoHeaYmi6dxLdesurnoaepACQVKAqyKn8=; b=Vfd0p84CEuTs+nQbMdohf1n6AXNRgdQgZv67HHWfq4drSC+mP+QOSaM6mL6BCunPuH IjgM5YMcgNMDl7fCq1+OV/mZBKaCt3IITldFmUwkqz+n4buLAFQrN/UpLO+oShVL2xok H6qLvQj0k2AOoufiemejgCwUexJ2NlY9HTEpk71tge5GgdWF16oCeKLXAtaNRg5WUKoJ ZR00/eLuT+QH96fWqDtKijgBAVD8cdTzx0R1bcRiWwpNVZBi/GhWkW+lgo0lLAqC8f07 7jeVQldxzaYW6UsMyUbjEw4q57bHd5bOZue8M1DSHsATMVy8Bdx4XXhcAltbh3wYgNjp ZWtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oGN+qVB5; 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 f63si12344017pgc.473.2018.12.11.08.25.15; Tue, 11 Dec 2018 08:25:30 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=oGN+qVB5; 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 S1727469AbeLKPnP (ORCPT + 99 others); Tue, 11 Dec 2018 10:43:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:59642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726919AbeLKPnN (ORCPT ); Tue, 11 Dec 2018 10:43:13 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 32F3320880; Tue, 11 Dec 2018 15:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544542992; bh=FiEsUDgBVmx7ZKwnsp7N1vK34T18XK0gSdd2mlyJH3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oGN+qVB5mAEIe4A/iL8a9Tx0NJLMZeRIzmdOyRfvGK3O1JYaAfXlRs8BUOG9sG0zN L5I0S1bo8FTdiZFBUlUfwCfU0rcm1DsGAvQ08ubDC0Bs8vJDb9FF705ne3PXszCmbE liriNBW9uHdUjfBFI9C2ABIeCDCiWs7+SzY27K+I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Wilck , Bart Van Assche , "Martin K. Petersen" Subject: [PATCH 3.18 26/54] scsi: scsi_devinfo: cleanly zero-pad devinfo strings Date: Tue, 11 Dec 2018 16:41:14 +0100 Message-Id: <20181211151547.472039485@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Wilck commit 81df022b688d43d2a3667518b2f755d384397910 upstream. Cleanly fill memory for "vendor" and "model" with 0-bytes for the "compatible" case rather than adding only a single 0 byte. This simplifies the devinfo code a a bit, and avoids mistakes in other places of the code (not in current upstream, but we had one such mistake in the SUSE kernel). [mkp: applied by hand and added braces] Signed-off-by: Martin Wilck Reviewed-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/scsi_devinfo.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) --- a/drivers/scsi/scsi_devinfo.c +++ b/drivers/scsi/scsi_devinfo.c @@ -33,7 +33,6 @@ struct scsi_dev_info_list_table { }; -static const char spaces[] = " "; /* 16 of them */ static unsigned scsi_default_dev_flags; static LIST_HEAD(scsi_dev_info_list); static char scsi_dev_flags[256]; @@ -290,20 +289,13 @@ static void scsi_strcpy_devinfo(char *na size_t from_length; from_length = strlen(from); - strncpy(to, from, min(to_length, from_length)); - if (from_length < to_length) { - if (compatible) { - /* - * NUL terminate the string if it is short. - */ - to[from_length] = '\0'; - } else { - /* - * space pad the string if it is short. - */ - strncpy(&to[from_length], spaces, - to_length - from_length); - } + /* this zero-pads the destination */ + strncpy(to, from, to_length); + if (from_length < to_length && !compatible) { + /* + * space pad the string if it is short. + */ + memset(&to[from_length], ' ', to_length - from_length); } if (from_length > to_length) printk(KERN_WARNING "%s: %s string '%s' is too long\n",