Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1144973pxb; Fri, 1 Apr 2022 05:58:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQMtWIDhclfvvv6GpcdJO5mMgVBWIpuow9c3PVpCiXqwwud8WL8AQGdGKVMd6+ZtZK7wax X-Received: by 2002:a17:90b:504:b0:1c7:3095:fd78 with SMTP id r4-20020a17090b050400b001c73095fd78mr11779002pjz.142.1648817917734; Fri, 01 Apr 2022 05:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648817917; cv=none; d=google.com; s=arc-20160816; b=o3km8eHrwnGE4bJLblWPhVcxy7+/3Mqz2ZXGvUU7H5kSgoe9U0AAtlT1bxv3TqEgnH SQwxI5BLOeh2dXAuWpCIIKC2Wscp79VlR8CBv4+bW1NbaNMyQgbe46GyOLA4WdhHXXNl UBBCmW2DSHj1r4gq8C219yVCrRPHDz5lwNwDuml35heH0PYgzHpXr99CvW8EK6imYekP rKxgN+weKp+YlTtOSey65ahncJrgJ4Uw16BtakVHLGcEfqAJR6qOXqpWHCZ7pV/KdunG le+I2SlYyl2fp+gnVAbl3GeGQXPfl8UpLqY63PAO8/3GFjKremO0XBigeIZPZO/+sl6B b/bQ== 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=VPFX6ypqDdT61mBwWRPD/L4KRpvY47RH05dHE7wwGzQ=; b=H9FIF+GcMUlGxPkLM1EtDD8JAogPbs35ufrFy3vzhrHeYUojsRSSFf9ke83l9oMCqe 2XR/3Ki6FIwbM2t3iVoKlMdKYN3RdFN6mKUbidc1lFi0uQwNwwbnItxbYKai0ad7xFeW cSO/SDMcqXIjCCeAnQ1ArLfz4O7XanwP8S/lvdrWFuYZMkYz+1hCXZZ0gRzJhGksr7w8 InFL8+g8i9m9qRDuDhS3DWxHJjSAVIyrl09s1uqCd55RQ5gGDxWAN4uwJKxlX9wiNUPM 2DCXFtnvM3A+U8D6bW64+9YueBLNwBa4D/4jct+IBBrip5UVK+zJ+yNtRokcV5OJNyNs yy1Q== 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 s190-20020a632cc7000000b0038160e4a2edsi2238337pgs.821.2022.04.01.05.58.10; Fri, 01 Apr 2022 05:58:37 -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 S1343943AbiDAHso (ORCPT + 99 others); Fri, 1 Apr 2022 03:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343944AbiDAHso (ORCPT ); Fri, 1 Apr 2022 03:48:44 -0400 Received: from mxout03.lancloud.ru (mxout03.lancloud.ru [45.84.86.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43BF25F659 for ; Fri, 1 Apr 2022 00:46:52 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout03.lancloud.ru E200120A6FA9 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 10:46:38 +0300 Message-ID: <20220401074640.3956695-6-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401074640.3956695-1-i.kamaletdinov@omp.ru> References: <20220401074640.3956695-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.34.0