Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2724050imj; Mon, 11 Feb 2019 07:32:29 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib0VzFl7N9VTs1iKWaQJ+HMS5WNt+19ksZW+glM3kG08ftoMwKX1gGprpJFAFNRAxn0ak5B X-Received: by 2002:a63:574e:: with SMTP id h14mr18136732pgm.336.1549899149338; Mon, 11 Feb 2019 07:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899149; cv=none; d=google.com; s=arc-20160816; b=eC+/u4E+bkazH9KljheMh0KtW+0eoPoPFtI+Ra2D1H99pZ6kMO4P0v5/fhaF3zYrza rKrPmQpSebDxtS3Ri1yyCPEmlOivdeIQIb4cTIJsy63DQs3FUgeu75ZTPBQrZqG78i8J TnOEk4klnpqE4GRxCdqAe1GP3OvI+I+35715Gy1pjwwuDNh+Q68fDI+aK7+30MSxyMv+ eB6uo4sbeVoB/o2FD1OrdTJwvQ1X2YCd/jZyI7fFBTrwM+H3r6DLVAA7kD28F+xTFFW0 etvjMRSaumqoaW//KNEBRtGqcDnEnwjQFRmcJelOzEUGU1DcPx2HrnR2w/i9LVC6R7at atkA== 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=3omRcCmUcFPeSY50481EaW7r99SGtPJ0e8C8o2G0yUs=; b=r4hvYbInU1UxQX44CbHfFeJk+tXKEcdmgT6UrmIu78Pwias2fhWAyHVk3/4EhwNfeH ErWqyHGEH3RHcTX/r4ECJ5S45Il9JcImUmN/M2EVqpMvmoOcMum4j9W/Bbi63qR0MCHn S+HJ6ixL0mpBKwQgzcRRhIoxKwVBAh/AsGqRA2LLEjAkpFX5ih/0E6fbw3cyLPlDOiQw Fzy+t7xaZSbGstpORcf61+bbaUztGW7CUURvEnSTmkCmyEZ4cm0GGdzPo9UCJWYCaoQE C/dPojBLvTSEu6YTfr4mYxhn9MgBJgJ1hrDDL9IJzUis/h7Zb6WcJcWo8/r/uunDV2mD sZLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yNZMyWoP; 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 f17si546856pff.171.2019.02.11.07.31.51; Mon, 11 Feb 2019 07:32:29 -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=yNZMyWoP; 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 S2388766AbfBKO43 (ORCPT + 99 others); Mon, 11 Feb 2019 09:56:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:43674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388529AbfBKO41 (ORCPT ); Mon, 11 Feb 2019 09:56:27 -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 0384B2229E; Mon, 11 Feb 2019 14:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896986; bh=COWvol0JpmUYIbhnJ/Y/HteLRxo8YNOVpm7c394iLlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yNZMyWoPHN8GoHuhJRwPnEMWdmpqM7EnE03GUQHWwL4vjIg/U5EZa4uVGsRUa55dq fm1tg4D8cSHf+o0Kv5/mqwfd2qZadWSbXdwrOh3TYtvIsNyrSLGBU/lQJKGgpWfgb2 bWi+GnAw/Ykk3ceBFs/4EMoR7vFeng2C249Jyifs= 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.14 023/205] Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1 Date: Mon, 11 Feb 2019 15:17:01 +0100 Message-Id: <20190211141828.629414099@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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. ------------------ [ 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 3965186b375a..62c9a503ae05 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c @@ -1172,6 +1172,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 @@ -1295,8 +1296,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