From patchwork Fri Sep 11 13:15:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11770535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1D4D746 for ; Fri, 11 Sep 2020 13:16:04 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F6EF208E4 for ; Fri, 11 Sep 2020 13:16:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F6EF208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kGitq-0002Bt-DT; Fri, 11 Sep 2020 13:15:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kGitp-0002Bn-J9 for xen-devel@lists.xenproject.org; Fri, 11 Sep 2020 13:15:33 +0000 X-Inumbo-ID: 0285a55a-a116-4504-8285-46939919917e Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0285a55a-a116-4504-8285-46939919917e; Fri, 11 Sep 2020 13:15:31 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 20BCDAE02; Fri, 11 Sep 2020 13:15:46 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH] tools/libs/stat: fix broken build Date: Fri, 11 Sep 2020 15:15:28 +0200 Message-Id: <20200911131528.19734-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Making getBridge() static triggered a build error with some gcc versions: error: 'strncpy' output may be truncated copying 15 bytes from a string of length 255 [-Werror=stringop-truncation] Fix that by printing a sane error message and bailing out in case the name of a bridge is too long. Fixes: 6d0ec053907794 ("tools: split libxenstat into new tools/libs/stat directory") Signed-off-by: Juergen Gross --- tools/libs/stat/xenstat_linux.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c index 793263f2b6..ce38b3433f 100644 --- a/tools/libs/stat/xenstat_linux.c +++ b/tools/libs/stat/xenstat_linux.c @@ -75,6 +75,12 @@ static void getBridge(char *excludeName, char *result, size_t resultLen) while ((de = readdir(d)) != NULL) { if ((strlen(de->d_name) > 0) && (de->d_name[0] != '.') && (strstr(de->d_name, excludeName) == NULL)) { + if (strlen(de->d_name) > resultLen - 1) { + fprintf(stderr, + "bridge name %s too long\n", + de->d_name); + break; + } sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name); if (access(tmp, F_OK) == 0) {