Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2648373imj; Mon, 11 Feb 2019 06:26:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IbwsYwP4XVYc3YykzPcaG3/rX2fM1mkXWfkUQuPj+nyqoeWGBCGsRBy3NCbLPPKAe+ArV6G X-Received: by 2002:a17:902:722:: with SMTP id 31mr37852813pli.271.1549895209347; Mon, 11 Feb 2019 06:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895209; cv=none; d=google.com; s=arc-20160816; b=RGvTxdzc1WWXn8aIAHbGyN7BEUnzQX/GXKlnA4L2IOJ8WawYSLnyAqJvuWQLYVZXa9 2QvnjrQXCfvM0MYl65fhVdjf2MNRQWBHC9kiBl9VRBERwA1fRKVPhWmTyuk6S+RI2IRC SOF0/bKfEy7FJtpOe9zsjoOiq9vAEFAsrbnlRp4c5/N9ZTGtTRlNZbgbozB8zu4N5v+1 RKVSFsh3h62CDZe2WgdfiPlirI5nm2jH5OM+g8SRic7PUIp2YBL/tp1zbI7bx9q87THQ S8Nd3jnfTlIt8lklXV2Nrc6g+hnBS8PuMPIXMmXF2vkNe8tqnVzSGBO3QC6VVuBSDKet /HlA== 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=n7cgUnc3DzFfVHnJ5f26rJuY1hb9vXD2Y1U+6DciAA8=; b=yItqOeHkG9cOUFMwNxr0rqcKa+QXwZEUoKi/FSffTIWy4VyPw7oEMrh5SMTIts2/Jt naRVx5gyjXW9MomRHTbtyxvpoId2N22x/W2s/QSwBZirYEQzW+qprb1PeTKQxgDSXR45 UJaumkWd/ZOpxjn6mkcvllOr7oUSVB9fR89MGhAA9W0CBs4GQSoTeelWgtYuGzVmBri7 AqmrJGsGLHwmCJQHRxti3pRYyeAHh37suKnFfdXoNg+SecFSzsV+SEdv+3p4gvB41W0Z LrVgo/SL8+GHYTNiNgwktXaMLVikly/tr4uVadM+fT2CHOAN/vBKBcWd0Wtmw0eunMYg bp4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ox6drZoB; 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 e15si9871547pgg.281.2019.02.11.06.26.33; Mon, 11 Feb 2019 06:26:49 -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=Ox6drZoB; 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 S1728015AbfBKOW2 (ORCPT + 99 others); Mon, 11 Feb 2019 09:22:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:55276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbfBKOWV (ORCPT ); Mon, 11 Feb 2019 09:22:21 -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 BEE60222A1; Mon, 11 Feb 2019 14:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549894941; bh=iZR26Q6xkex2tEhRSm7+dZ0bFobj22YCAxUrycMhFmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ox6drZoB/6mxb/SveC0PsVTIRP+GAf0nIbdALU2laqIuXJoz5Ey4B0fSNd2vby+G7 2HsZaHCYLiL14rSHq0Ob3E8ju5VTZ7ogtwx7gOGw3kdoA+WcfviZkHFtcbSIXErC1s +dMQ+quIHFZ+7SVXCtsa4ggEx7zvQ7EVD9HVC7wQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Sasha Levin Subject: [PATCH 4.20 038/352] Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1 Date: Mon, 11 Feb 2019 15:14:25 +0100 Message-Id: <20190211141848.745977693@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@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.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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