Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3710215imu; Mon, 28 Jan 2019 09:25:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN5knbQUv3iQFYnfKaMivdXOzz2mAF5NBKn94kxio9dxpIaGf2yf8YNfSOLgp64NPO4BLI+k X-Received: by 2002:a17:902:583:: with SMTP id f3mr23208712plf.202.1548696342701; Mon, 28 Jan 2019 09:25:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696342; cv=none; d=google.com; s=arc-20160816; b=R1fhAVSuRdVGxCepofi3xONf96CdYkiL2SVH/XZhh5H1u2vCFcZtFG4Tt6BNX2qtQp lgk6+dvWsyMQQHjiQEgwA+lfG6NuVvhj5iYikpS9FnjVn85xxUSmd5Ql7PQQpnFL2epm /+07pOTPbaUx1xwGHGBVg5cQNXaRzwsBRz4QIHpOziJJn2yuF0cNIHhcngmTWjJhruKF NwB+baE/0WjR5kuqDQiQDrJr4Z7ixwxLN8Gi+kfKyR/UkHaiHfodc8k5/DexuSb+aa7L yEOzu5T+bODWHDsy2Ke4cW4wmv6zQVQtSo2zWfjCS8uiQVRrO/5c3eFNSWkry+RO5Eqz ACVg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xyDOvDy+qu/Z/HBL6fckKG8bq1rMChVstyNIsQrTXsg=; b=WlBPSTr7n0rrM4ZtphVVIyC2oLJ/RA6PijsZo7/pdINWk+HoyRLhzG0jV4Xnjh6pE6 Kka1M/HCyr8KbaQQUwIfsytroyguKTHSmeCbzKtbqtMYDaUoMeHlLH3NRpMvHx3gX0ny mdLgVsbTxWNUpwQRzsG8tZi8EbKF8ke2SZdw1imBNY5qVZ8Q1OeS/HtQgVYzs33I++vw goBCdYLUvkjqdGdFz6y4Odg0FnmK1CkaLMt41Z1EG2I8Wh0J7nwOKTnQBhiv1NGAuHRy SGyNV1+L0tar3ZGvTdL6pXfBLc1uCX4S+Ca+JJPZge94Y4bC+/bXVWvhqBPnMyF/dPEO xRMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SB0hc4tr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3si32428415plk.199.2019.01.28.09.25.27; Mon, 28 Jan 2019 09:25:42 -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=SB0hc4tr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730972AbfA1QBN (ORCPT + 99 others); Mon, 28 Jan 2019 11:01:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:46436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730946AbfA1QBH (ORCPT ); Mon, 28 Jan 2019 11:01:07 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C296E21852; Mon, 28 Jan 2019 16:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691266; bh=GyYn+I/ayuTEeEBqIWMngxUA+5RZ3EjZpdkLEnVhJGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SB0hc4trPCgMwkuavBUIuwjwzBoquJlbaxv7NuKw4P4tJKKcAmKzQw5e1H3Qfol2w xTFHNtR0XBAMvnFDGD8+4A4auSb+RRoaprnI1pownNVo3IybSWzbCnw77GqxnVhmCp hEdKxylAPlSTUa37W16mcVLQ8s2l0p2HZcgFoRi0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dexuan Cui , "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Greg Kroah-Hartman , Sasha Levin , devel@linuxdriverproject.org Subject: [PATCH AUTOSEL 4.19 038/258] Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1 Date: Mon, 28 Jan 2019 10:55:44 -0500 Message-Id: <20190128155924.51521-38-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui [ Upstream commit 4fcba7802c3e15a6e56e255871d6c72f829b9dd8 ] The patch fixes: hv_kvp_daemon.c: In function 'kvp_set_ip_info': hv_kvp_daemon.c:1305:2: note: 'snprintf' output between 41 and 4136 bytes into a destination of size 4096 The "(unsigned int)str_len" is to avoid: hv_kvp_daemon.c:1309:30: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare] Signed-off-by: Dexuan Cui Cc: K. Y. Srinivasan Cc: Haiyang Zhang Cc: Stephen Hemminger Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- tools/hv/hv_kvp_daemon.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index bbb2a8ef367c..d7e06fe0270e 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c @@ -1178,6 +1178,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) FILE *file; char cmd[PATH_MAX]; char *mac_addr; + int str_len; /* * Set the configuration for the specified interface with @@ -1301,8 +1302,18 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) * invoke the external script to do its magic. */ - snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s", - "hv_set_ifconfig", if_file); + str_len = snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s", + "hv_set_ifconfig", if_file); + /* + * This is a little overcautious, but it's necessary to suppress some + * false warnings from gcc 8.0.1. + */ + if (str_len <= 0 || (unsigned int)str_len >= sizeof(cmd)) { + syslog(LOG_ERR, "Cmd '%s' (len=%d) may be too long", + cmd, str_len); + return HV_E_FAIL; + } + if (system(cmd)) { syslog(LOG_ERR, "Failed to execute cmd '%s'; error: %d %s", cmd, errno, strerror(errno)); -- 2.19.1