Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10784964imu; Thu, 6 Dec 2018 06:47:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xe+kSItYds685/dOvIGW6o7oux2H5+W7KvBWJ4QpsvtG17WG9huLTYiVCY60h3T87WKuUJ X-Received: by 2002:a63:f412:: with SMTP id g18mr24661461pgi.262.1544107651827; Thu, 06 Dec 2018 06:47:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544107651; cv=none; d=google.com; s=arc-20160816; b=sElJesz0nXLKeyI5BaVIDLexyn3BaKGqg8ChUGOCkKISTBKOb4q0lC/8kFrSCue43T HspqASCpfBl/YEv1IhOOXuHqO7kulaZB0u1QCp1VdXngdRSiZT6VJmfagSAGn0awU2ta luTxkqf16NoyB387WUopCpHFReST9tDeMZll9s3po7/GwhufiXrz5wh3W+QGGEdMM06I 02nDDvne9U/CKX9Qu/gE/MTpx05aclrtoz7z0XG6U/pa1m1PEuN5qeYUJH0Hj8xmIy5p HAmxyvXzTwiKHJIl72wrj8sSVGkpH7XMmcMB4q7kl6rVj/XT/HwBz7tBIFzBGeRb/irU T+rg== 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=ji24UltjYbBnYGJI3Ewrk+gCHYinsAQRCxD+GnOtpvI=; b=urzPiqNVhG3P+scGJz9Q4sAB+PBGlmG8LoXBQCj8csAbQKdxQ+uKnbdxVpnP54ZIJ2 vlhYYWaUeyo807xQ+6QqKYIFEtW8RqZS3q3IkTrmbvndAnyY46L0Uagg6ZTaz5nJQQrM TMdleMChTq79cZo0NSUtGI9qw0KwQOr0otYb4VxYPdLlHHKV4LRiav5GPwaLxtzJZWy0 57ThOQRHNyseY7nUXBBTchMVlE7e3lxHH/nKvr6TezQ1LWU5iSuBwlv7FgL0mQCAukfT TF7NpkX5xaS1RUGvPAGZoIcyjheiVTpOKY2oYLQoo/fKdeHcrGzq8VGr9b8e2XmZzL1j PP7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=12MNSZis; 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 v21si373288plo.417.2018.12.06.06.47.16; Thu, 06 Dec 2018 06:47:31 -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=12MNSZis; 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 S1730125AbeLFOnz (ORCPT + 99 others); Thu, 6 Dec 2018 09:43:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:48440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbeLFOny (ORCPT ); Thu, 6 Dec 2018 09:43:54 -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 7804B20892; Thu, 6 Dec 2018 14:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107433; bh=Xm9oyUH/QP09u9bwidpFqjfbiwAbBi8O//Snh22h8oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=12MNSZisfiGJQ6qGzlOniNyNjldWijXslfeoNzpBw1tPZyE6bAJvjFoLs7mbWKYPP TQnNyhRHeY9d02jNSt8dRKxRfSzPnnIQXX34aJkCCm6AYTL0+pmr3/I6P9O1jf+oTN 3QMi9oyVG6AGW3FbjUyT1LPhzebKdXt1Lg49hz8w= 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.14 26/55] scsi: scsi_devinfo: cleanly zero-pad devinfo strings Date: Thu, 6 Dec 2018 15:39:00 +0100 Message-Id: <20181206143003.153455326@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143001.749982936@linuxfoundation.org> References: <20181206143001.749982936@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.14-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 @@ -34,7 +34,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]; @@ -296,20 +295,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",