Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp800514imu; Tue, 11 Dec 2018 07:47:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/XMx1P0tm6i47PmS2wG7HFjcGyyppa94lCOspHMARLCawZfpnhI4G4dTBmP6a1kbPwfgyG8 X-Received: by 2002:a63:1d1d:: with SMTP id d29mr15168292pgd.49.1544543277587; Tue, 11 Dec 2018 07:47:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543277; cv=none; d=google.com; s=arc-20160816; b=Xf1iBe15Q2C5J2ekGxabGt+g2kFYlC8mVx70TGPinfuYcJOfx6DzKjZd7kgJmRtPTV xQPc4tWpMpZcDnaLWn+YcTyxcuTrbAVmk8VT1NmqQPytpxOhN+J/mHIeHBCuhrVro2UP cQEzhrpvr4P0Y4h+EExsRhYRi/70Q7SZNUuVjP28RXF/sfORJSxQjIqjiGIy03bmYCVu cH1/ntRp7JcpoirZfsvBx3IEy1MQKIC2nbeW+ISxsgWZQXmbA+daxaR24TACpCNVAhUX 6bFzMPEssLvM5tCkIT9pRmJIRsjW5RUeDuyhsa7UxI/LGc+w9s9HiAnp8+IIZIXiHBPB d3ZQ== 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=9K40NeHRK6IGbNr+SR9cW8oSUbcaoEjrAuCEBFRGlyM=; b=zXfqdn+uTQaPyaZv+XYe7W26ivun+TMhtDg74Izyvnp4wG0LafUjtN2TS/S57ncUFB y3QuapnBAUberuQkv4BdwURCgNe9GaIF1C1N5NEKuUAVx6rC+zIBrvvzUfr5sSU9l9Xu j0uW8ogO9sArwaYJfHkb3THhZAZue3MZUrxuSh15oQCzJG2BULTcCG4TAm1VCzw9myFY 8CjLFI/HUvLKbIzh0t5Pv5OzzfpGMNU7ze3e647WDoYq/kz3HWcQHQYMQWJQU2ysn845 QNhkWJ4GWY+VOlJjSWAaGO6tnWmUsH4a02oT7r35C2PkLsuUm45FmEHrVpiKOhXeX8Hp kr6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uqjfoFnX; 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 u202si12262059pgb.115.2018.12.11.07.47.43; Tue, 11 Dec 2018 07:47:57 -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=uqjfoFnX; 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 S1728281AbeLKPqJ (ORCPT + 99 others); Tue, 11 Dec 2018 10:46:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:34536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728267AbeLKPqH (ORCPT ); Tue, 11 Dec 2018 10:46:07 -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 A32CB20870; Tue, 11 Dec 2018 15:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543166; bh=h2ntuOz7hLAOg4vAnpOmOozN0SBudiB50YXtJOKNrOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uqjfoFnXm9n0qu2v3zhDdIWhaLrPQavPDl/uuM2iOfX1KEAXGrEtpESTF9r+iQYaq OTTuV6Zm9Z9Jwt13TdZAXBWoU2XHFARH2y8XNq+FGDEfLPeBI8qPOri5bf434MNKOa tnUwjcYpR1+4uTlLay/DQD3FuVGCj0vrU8++k1gQ= 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 4.4 37/91] scsi: scsi_devinfo: cleanly zero-pad devinfo strings Date: Tue, 11 Dec 2018 16:40:56 +0100 Message-Id: <20181211151608.862217772@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@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 4.4-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]; @@ -291,20 +290,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",