Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1148971pxb; Fri, 1 Apr 2022 06:03:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfNFDr7sr5pUMWjzLy1hRTVNjIbesZP3MHvY/Rp7Vx/ADY1V4gb+o6zRagDO/IHMSUwKfY X-Received: by 2002:a17:907:9718:b0:6e0:6faa:3aa with SMTP id jg24-20020a170907971800b006e06faa03aamr9326514ejc.307.1648818210368; Fri, 01 Apr 2022 06:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648818210; cv=none; d=google.com; s=arc-20160816; b=SIB0dJ03VfGFFDYMuKNoNRLfgKtR80eVSRa1dS9ZoopQc4D7/aHbtMxtM7Qba3WZUa DjYaJhFGCh0Ir2TrRNSlVeyw09jkTK3jF+svbm5+8nNFCiIzxifNqOFwByj573jZ7i0+ rXCeTPJ/DqLgsr1Vz250Uqz3tXHT7gTFUNVV1zwMtdFy/KAXjYr45H7oqaVAtAJfKGKJ UOmw/0iaFhAh+2WEjR/xeX/iRqV4bMH7wlHzLcPS75r8dwNLB7evRN35w3JwhqOZXfXd XhbgcNpcxbS8b7CG9Gf0rwj5W548PFABxFLZrL7jbE0vKl+QEyvc7cFpxuXA9q9oMMgp xRCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-filter; bh=F3lZgv8wgG+3IHAeGBigV9oKIlHye5E0ZmKg0K3mFzk=; b=PDlYiEm/wU/43DNsf3LQ/49AxfupjZdEpUbZcfmcSvoOncvsX2P+oi3Zc1RGK93iYm Xglshy6/6iP8mM9RI+uVrPeNG52B0w/OIyugg/d42rjs5VHHpM18cWx+jt3cEGz4RuLn ltBxdIAPfadCxGijjL+WeGidVNri4YvxL+U4ba/kYXZQEGuzx1Ay2JPkFipXux5hseSh rzssRQcUDxX866GRjX3/UtYaqiEoqIVzd4KS7+UeScTQzMJx341gffuyO1Pgej2do4Jh hC3fjQ5Q0lPSCjI8mXP2iBGYZBZTpFIUfUNRsoVY0UkfbFH/IoM5kJMW5xXgpCPi3d1E ++nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020a056402510a00b004190b6bd098si1825021edd.234.2022.04.01.06.02.52; Fri, 01 Apr 2022 06:03:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344205AbiDAMSq (ORCPT + 99 others); Fri, 1 Apr 2022 08:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231462AbiDAMSn (ORCPT ); Fri, 1 Apr 2022 08:18:43 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146C527796E for ; Fri, 1 Apr 2022 05:16:53 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru 7D18520D30AC Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 4/6] tools: Limit width of fields in sscanf Date: Fri, 1 Apr 2022 15:16:45 +0300 Message-ID: <20220401121647.3985682-5-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401121647.3985682-1-i.kamaletdinov@omp.ru> References: <20220401121647.3985682-1-i.kamaletdinov@omp.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT02.lancloud.ru (fd00:f066::142) To LFEX1910.lancloud.ru (fd00:f066::80) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org In tools/btmgmt.c and tools/hex2hcd.c few sscanf does not limit width of fields. This could lead to static overflow and stack corruption. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. --- tools/btmgmt.c | 2 +- tools/hex2hcd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 42ef9acef..8f63f12ba 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -5164,7 +5164,7 @@ static bool str2pattern(struct mgmt_adv_pattern *pattern, const char *str) char pattern_str[62] = { 0 }; char tmp; - if (sscanf(str, "%2hhx%n:%2hhx%n:%s", &pattern->ad_type, &type_len, + if (sscanf(str, "%2hhx%n:%2hhx%n:%61s", &pattern->ad_type, &type_len, &pattern->offset, &offset_end_pos, pattern_str) != 3) return false; diff --git a/tools/hex2hcd.c b/tools/hex2hcd.c index 674d62744..e6dca5a81 100644 --- a/tools/hex2hcd.c +++ b/tools/hex2hcd.c @@ -248,7 +248,7 @@ static void ver_parse_file(const char *pathname) memset(ver, 0, sizeof(*ver)); - if (sscanf(pathname, "%[A-Z0-9]_%3c.%3c.%3c.%4c.%4c.hex", + if (sscanf(pathname, "%19[A-Z0-9]_%3c.%3c.%3c.%4c.%4c.hex", ver->name, ver->major, ver->minor, ver->build, dummy1, dummy2) != 6) { printf("\t/* failed to parse %s */\n", pathname); -- 2.35.1