Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1271832pxb; Fri, 1 Apr 2022 08:55:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS6kAHMFA6Ejp6EztTbFGJTUZWmavKxGWXvN5rPsjrXDAfbYaS4+ukYt4uTGjD35vFt4T7 X-Received: by 2002:a17:906:3918:b0:6e0:5bbd:bf33 with SMTP id f24-20020a170906391800b006e05bbdbf33mr385813eje.764.1648828546818; Fri, 01 Apr 2022 08:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648828546; cv=none; d=google.com; s=arc-20160816; b=mkpT+JGC7U2g+p2ndVeSAZiUBBx7y7Q8rvGmkX2Xr+2bTYWff3JuXWthM/RmwEhPBZ q3Vjh7PNnwKgIU11ShKwtY4Z3BZMDHkU5J9TgPBT/QvYa++8Dl2mUlczee9maZmglN9/ /hXISX6utmz18PpAvcZ5tEBx+Y+iRKJAOx4/Cf6w568Po/eTwC4ZpRwojXBThKMheQYn AVYqXv6m7QI8FZgHVDVM3aSUopJf/OfmRfPtXT7BdtScRT14vsgDW92MEZSQIXiztzfb +VuHXzP2L858r+uwUP3cDrgRMo8WZOmSGUUcIdtpqBAYohgs8z/ZI6HghIQc/xqf6NsQ agnA== 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=oproek0xqO/sPw5ZtSihjw/oaafYxuX7J8PmlbNS6MyMkLz//TGYuUKEB49s5zx3zJ pHFFFLcbCqpa6dfRrQkywRFeFnBpC/59USA6q2h25/jj1f2qj9zgY8QkMiU7Eu/mmhd2 kA+v/j3SVGUuoWlMt1ZLUSEovzrKXjYM235pyxURoW0Fdg0VWkLpCTOSDsPr1ukzTvDx +ENEHQ94vuYeFPQLayg8qRwWmtKs3V9FkL5KmeJg6HunwHF49P6TFItD8UPKeVCv5L4q bOpsf6/E0F8umsybZx5dbErWXN3nGF7EgAfn+JBQ9Eqz0Nyd6zQxMaizqCaO91yoQmY3 sR+g== 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 c10-20020a50cf0a000000b00418c2b5bd35si2018335edk.23.2022.04.01.08.55.21; Fri, 01 Apr 2022 08:55:46 -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 S1343590AbiDAKaD (ORCPT + 99 others); Fri, 1 Apr 2022 06:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245676AbiDAK35 (ORCPT ); Fri, 1 Apr 2022 06:29:57 -0400 Received: from mxout02.lancloud.ru (mxout02.lancloud.ru [45.84.86.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1B9C26E744 for ; Fri, 1 Apr 2022 03:28:05 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout02.lancloud.ru 0B93F2304856 Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 5/7] tools: Limit width of fields in sscanf Date: Fri, 1 Apr 2022 13:27:55 +0300 Message-ID: <20220401102757.3960551-6-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401102757.3960551-1-i.kamaletdinov@omp.ru> References: <20220401102757.3960551-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: LFEXT01.lancloud.ru (fd00:f066::141) 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