Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1232242pxb; Fri, 1 Apr 2022 08:02:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsWr02fw32jIOAj64oZN4qtI/Z7n9XTWZl8CUoK4zhAoV77T+d+v1ErPjlLvJgir+fhRU1 X-Received: by 2002:a17:907:96ab:b0:6d7:1720:15d6 with SMTP id hd43-20020a17090796ab00b006d7172015d6mr213768ejc.322.1648825349443; Fri, 01 Apr 2022 08:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648825349; cv=none; d=google.com; s=arc-20160816; b=aowIkIJWtGxB/gJKFndgBQcc4GTm619EG2htoEeicxbW7NPLR31toMokn/9yMCva3L c4s71lnOdQD/wBYXEd2Ra59AlAtHh4Yqw4vQU7Oqoh6oW0QTEN0b3zz+iA8LP2DBdb1e nnhIDvZ/0e2IC4F4jqZ5wpPfexDx1N0RYxFM/miEL/vGXYEjZlHKfE7ayf4yoJyxOuBT KSZxOEkttA0DMCrw5LBUt9VnP94/KFLKwH+qGN1Mg48XKa9z1fvHaJMY0DtR8guw1hL/ tJmGAIRocGzbttg9mExd2UXDXw6J/MGn7BHzOuVbAaQh53x/aJCkdca7qTfoIwPX70Fn GD9A== 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=yXkL2qLr7cO7pXGKGPZ0EDHBe9tPZ8K19tnXPKvl+rnk8wfe82cbT8Vs/Xle9zr9va 8K7TIIlolcYAVBaPvhBclWi5SunM5pMOTahtG/Gg04gP55bVqqDimAHS+faDDoHVEkq7 fs+blJWdJe7UHaCGMCW5/t0jMk1+wf5ELVNZ+iG+KQh+iKT4Br99m85DxEtbapuN6CmH WuY6Ck+1EgoDbSS0ig3kzJzCBht9HSID02euIlet4rpoLa+IRIiPjbX/fnu3qH0/dXsH vXtPvfdVR67o1Ov+MUg3htDfSW2gj0FHNoJY+mDVYark9edzwS7vYNb1nZhqEPcari2y 9a2g== 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 p21-20020a170906839500b006e112c69f51si1635394ejx.811.2022.04.01.08.01.58; Fri, 01 Apr 2022 08:02:29 -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 S245708AbiDAMSn (ORCPT + 99 others); Fri, 1 Apr 2022 08:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231462AbiDAMSm (ORCPT ); Fri, 1 Apr 2022 08:18:42 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BACC027796C for ; Fri, 1 Apr 2022 05:16:52 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru 51EE420D30A9 Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 3/6] tools: Fix signed integer overflow in btsnoop.c Date: Fri, 1 Apr 2022 15:16:44 +0300 Message-ID: <20220401121647.3985682-4-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 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