Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1902058pxb; Sat, 2 Apr 2022 07:38:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLkqC/nRxYHZn3Ivw8xjgXqTHw6tXs639DUFoQix0Ja1W1GglnS0rFtpxRxA7eh6nyzTDd X-Received: by 2002:a63:5c52:0:b0:399:8cd:6003 with SMTP id n18-20020a635c52000000b0039908cd6003mr435150pgm.211.1648910292270; Sat, 02 Apr 2022 07:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648910292; cv=none; d=google.com; s=arc-20160816; b=RtnWhoijBx6KFy137Y5l8e/HAKUU8DvAszlNBYYMFqf5vOa06zA1iBwAguFHvJbDZk IGWVZ5CTEZEpJbUf6gQFH7MO69A8Nnmvfn912I+UQY6uGWR5+SLRzmPgnM+vTRKDDDXr yEJL2YLtormHp9YOFFpFnnByOnROsBMCuphGO7Wvw+pbEz5h/hZQ/vM6w0qcR7tfuJK1 TUInGFkrVhK+GkMIj59w/yDmV+i8qgRytdXteuDuo6Zyohy8hIq0azvKN1up+Y9lGude Wxye/Y1ClHwp35gJc0kqKJDwBZwtsQDrf3AMsPYUOyoC4ppKDE5FfvDfO9t2o3KizzF3 dwpg== 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=sekwOEJpYIA5pHno+oZk/OeECxPMFxzjhvIUcOBkXymBcKtdHUPQS1z2bgk1OcWs6l 1/pXFYzY2qIkofbtAFC3BYU0YqJBdt4p48Yr6A1SOJY27D2srpBk0p5022dbU2q6XMFU 0/YFxG8oDgdoWEOsza8EgqJsIOTKblU9+P9tMDYBSUC3ud7eH19RDoMeTzmJYrpumvvN KRPIgzDKsvbB1L706AnbhEoOL4b3E8eGB/mTTLVDzV1qCoRxDrDuBcAgYkC1dMlj8vhA AtQ+QKmONifJ/aR1DIetb5BSheKJqb2buy8wzHNZlvnNCvb5O9d9Cp+Fbb0XH1Nij/7q oEDQ== 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 z10-20020a170902ccca00b001567d82c09asi1709113ple.174.2022.04.02.07.37.14; Sat, 02 Apr 2022 07:38:12 -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 S1345372AbiDALQL (ORCPT + 99 others); Fri, 1 Apr 2022 07:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345366AbiDALQK (ORCPT ); Fri, 1 Apr 2022 07:16:10 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F9012E14B for ; Fri, 1 Apr 2022 04:14:16 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru 6BB1A20CBB8A 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 14:14:06 +0300 Message-ID: <20220401111408.3961844-6-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401111408.3961844-1-i.kamaletdinov@omp.ru> References: <20220401111408.3961844-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