Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1269332pxb; Fri, 1 Apr 2022 08:52:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgxhao3mt8fx8JnJ7xzCkfGlEtMk+57/LFHOwgPPQpeggQTn/Julur5opb4HHyI1ekBbEN X-Received: by 2002:aa7:da81:0:b0:419:11e8:1039 with SMTP id q1-20020aa7da81000000b0041911e81039mr21690593eds.285.1648828320322; Fri, 01 Apr 2022 08:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648828320; cv=none; d=google.com; s=arc-20160816; b=NoC5z+Oc1lkK41Gd8dqaK4oGyrSbfMcwV5vETahmMN0YshfXR564sYOAOdIT8/QDWS PwaIqnWHJcCKeSBYiIxTxA33QsamVcDgM7DZVnqkXXLa4bd57XXXvPA3fTraN1h8Ay6V hrun9iEeuMMDaFLBnuWj7eh4In1a035uZIB61mSF3WjscyP10/D/2yegQh2pByBFIdtz ILBOY9/JlCIWFT8DspxB5ReEi7LW6R77CmJHZOMWbN4Sz+CgmnSR4M60KNFXpBDpAowp 1hyy8+J+BBjbuXFRMZsWxziCM8u3J/Xkjv1L5JK0UfXCgcCltK5vqtizM2zRwnVXTmca MBIw== 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=FK0CTCH0KSxQ7Bcq9LzWvqXMquboUZeeby3s8OGd6oM=; b=afgUi1tyAG4Hq7NEOz6bxcAjYwY3bOmqlqSkJhcaYzgzYxlE5Dghz1Iqt7qEyloKlL jZ0SIhah5AC6GH7PivwCD+PWJFr3Dp8mCr+47X1IP3+P9d9E2BkXbqkbs5H0ovgmCbYw QSKNZwsg2N1kedYzFwN2eao2aackDhru8xxtvKAzLUzI7G4U+z8ohk2Xx5Wu1zeRxlYC xhzTFJxVgp8xjGLWbdE3OFfA/tvtz2oMKD4Dpl3xWNyzRMbNG9FJmLI8y9BpNBr7P7DC FtX/39hxAEbLYyAnUkR+C9yHNXwvxtOcLYhHx46nhqE2Ho1rx1k8N352L07zcwIAJ0ld SGbg== 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 y4-20020a170906558400b006e055c9c954si1765984ejp.552.2022.04.01.08.51.30; Fri, 01 Apr 2022 08:52:00 -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 S1345370AbiDALQO (ORCPT + 99 others); Fri, 1 Apr 2022 07:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345373AbiDALQL (ORCPT ); Fri, 1 Apr 2022 07:16:11 -0400 Received: from mxout02.lancloud.ru (mxout02.lancloud.ru [45.84.86.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75CE131961 for ; Fri, 1 Apr 2022 04:14:16 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout02.lancloud.ru D4A0A23076CD Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 3/7] tools: Fix signed integer overflow in btsnoop.c Date: Fri, 1 Apr 2022 14:14:04 +0300 Message-ID: <20220401111408.3961844-4-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 If malformed packet is proceed with zero 'size' field we will face with wrong behaviour of write() call. Value 'toread - 1' gives wrong sign for value 'written' (-1) in write() call. To prevent this we should check that 'toread' is not equal to zero. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. --- tools/btsnoop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/btsnoop.c b/tools/btsnoop.c index 738027dfc..a0d6cf356 100644 --- a/tools/btsnoop.c +++ b/tools/btsnoop.c @@ -193,7 +193,7 @@ next_packet: flags = be32toh(input_pkt[select_input].flags); len = read(input_fd[select_input], buf, toread); - if (len < 0 || len != (ssize_t) toread) { + if (toread == 0 || len < 0 || len != (ssize_t) toread) { close(input_fd[select_input]); input_fd[select_input] = -1; goto next_packet; -- 2.35.1