Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10794540imu; Thu, 6 Dec 2018 06:56:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/UfM/KErdqqVHkROSIfeAG5gicD41klhtt/ms8HsITEvQjtfSa+25wbnio85by1CyCzQHlz X-Received: by 2002:a17:902:c85:: with SMTP id 5mr28989081plt.339.1544108215116; Thu, 06 Dec 2018 06:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544108215; cv=none; d=google.com; s=arc-20160816; b=PgZvBU2bAiu8N2aZKbqQIr3EG7k3RRgFAxgpo0dgLrAcYS8lTg5DgAxGwQ95TVAofJ THwSKfxzTbX9GdeaYwFUOpQsgDO+6aVa8nqId77blSbGHoPyKnS0S72/kNRqmlg1LjyV PAK26hV03mTg1a7d4TNdZWArOwfmeBfAjAAE4cOyXiAZh8xjDSWhUk192MUdnNJsUMF9 VrYThzv6gsTAtsK7mtYOWVKbuEF4zsDZGUR1gd92RsLYxy0LvG+1d5SNHGWTdLj5tn0l CYjfTTzYZoGMQVD1aldbYboenV35O1rD8CT0JdRRQgztOW2niR7F1l38i5u2NfWjGvTD 2u8Q== 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=Fu84K8OnbCnw3JCkGb4bZsVzeWY52p63yoGooq3ZDKE=; b=tyisrNkhqMuGk5weXmUX8/h1cabAJI5K6BFCCU183vUVXP+6gqRQoUqulgiuH0D5JT mdg/sP8OCbneN+BH48o5k1OwBHBd2WKO3S96miYhezBzne7/IGxvY4b6VyRn8Eo8k/t3 +c5uGrO2mU87UDZ1uPi+fvCfWLYFkBQEHydLFu/g+FX9U8I2v+9AN1+Kn7G428hAHTmb fjJIxxH/u4s54zeS4l6ewLxOc6tdVHzacqHVk9+NVkbc4la3oQXjciN5ao6g+vE0JweN ZhzLFjlOaRV5tShSTcvwmnFQhzoYzaacGZLTUReQvKkTDUDj9zz3TQc67ZJxIUOontwB ruWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hkbVJ8iS; 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 l61si449219plb.6.2018.12.06.06.56.37; Thu, 06 Dec 2018 06:56:55 -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=hkbVJ8iS; 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 S1726359AbeLFOyk (ORCPT + 99 others); Thu, 6 Dec 2018 09:54:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:49286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730896AbeLFOog (ORCPT ); Thu, 6 Dec 2018 09:44:36 -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 62A2B20892; Thu, 6 Dec 2018 14:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107475; bh=8gC1egxPn2V3GXwf8nm93yuSmw6+XwkV9/h/agyIlEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hkbVJ8iSq9g0VDIowMuT0WvxLPTu7ErqCpC+FD22A7BR+UGYoaQef1x8N6TW4fNxe 3VK0IC8fcQCgZAekRKIakBoZRym+GDX6sG6C98ywtYf0xnBcsVX/iry/r7w+TXyHWT EYVrObBwW2xwj/Qn9znq0hD4XaaXGpjPXiJRPjQE= 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.9 020/101] scsi: scsi_devinfo: cleanly zero-pad devinfo strings Date: Thu, 6 Dec 2018 15:38:19 +0100 Message-Id: <20181206143012.776973654@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@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.9-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]; @@ -298,20 +297,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",