From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA52C5ACCC for ; Thu, 18 Oct 2018 05:10:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BF3A2083A for ; Thu, 18 Oct 2018 05:10:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BF3A2083A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxonhyperv.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727600AbeJRNJo (ORCPT ); Thu, 18 Oct 2018 09:09:44 -0400 Received: from a2nlsmtp01-03.prod.iad2.secureserver.net ([198.71.225.37]:56296 "EHLO a2nlsmtp01-03.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727476AbeJRNJo (ORCPT ); Thu, 18 Oct 2018 09:09:44 -0400 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with ESMTP id D0YwgNWyoWzu3D0Ywg1cq7; Wed, 17 Oct 2018 22:09:34 -0700 x-originating-ip: 107.180.71.197 Received: from kys by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.91) (envelope-from ) id 1gD0Yw-0007He-EH; Wed, 17 Oct 2018 22:09:34 -0700 From: kys@linuxonhyperv.com To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com, sthemmin@microsoft.com, Michael.H.Kelley@microsoft.com, vkuznets@redhat.com Cc: Dexuan Cui , "K . Y . Srinivasan" , Haiyang Zhang Subject: [PATCH V2 5/5] Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1 Date: Thu, 18 Oct 2018 05:09:32 +0000 Message-Id: <20181018050932.27932-5-kys@linuxonhyperv.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181018050932.27932-1-kys@linuxonhyperv.com> References: <20181018050835.27828-1-kys@linuxonhyperv.com> <20181018050932.27932-1-kys@linuxonhyperv.com> Reply-To: kys@microsoft.com X-CMAE-Envelope: MS4wfBsrN4ux0LluePOYZFkM0APtb4tjOcEC9b2SwwsnVwY/h0UEY4m/MSwC6oijWZjG3ska7zq/6Fg+21fR2vXZ4cYF/ecgkrfO6fdZA5cadlq6Jz3oyyYk wKN6fjyF2VnD1A7+nGTTITaEBdGOhm2p0qcFEJ6Bn5n7d3RCx1ZCuyLRzSxbn+37beNlpU7IIcGGpQNNFCPllhAPelHohtSTytgpsWcHN6E4lJP0PQPs6VYJ MeXQh+p97ovh3UnPqp0ZD9ac4e7UleYq52sR8+sTBF549kzPBgNrasidItR/EqQ8wAb69dIF0O5S+7XGeVbSbQKV8U1hVgD5AXTHGu60AX1oVX4tR25ocqfl EOxcBkrjIqnrTnuXlESrveKVWT+7U6YgePOqsRpbE/6Zrd4AOZ0Uxzp6G3iaysE9C5EyRunmIWnR7wBNM/zNO4SpN0JxpjtFF9xo+fjcUnSgvkurl5rKBo1r t/fhNuYGxfY9Uakbh7ZTm8c4VFHpp2h6ADmXSUtnMo2CEb0U+VN5oPNKmTlPSRdaA5rNSTC8FaIKD9eccabLzik0VWAlUNfF9OLji8f8P3zPSJXBg9WeUS0T /2mr1RNmrp0GtiLQn/qP61eX Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui 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 --- 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.18.0