Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1792607pxb; Sat, 2 Apr 2022 03:51:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCmp6Ovacwl4i9dC6urBS0JFwC7Fn9VPw4225awiQgmwOq5dku7aXtJx+2TxeNKUPuzYFo X-Received: by 2002:a05:6402:5111:b0:419:74a6:6dc0 with SMTP id m17-20020a056402511100b0041974a66dc0mr24869849edd.293.1648896702746; Sat, 02 Apr 2022 03:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648896702; cv=none; d=google.com; s=arc-20160816; b=CRe9z8yfrnqry23T3/7IysBcmcHIHFzpnjQ85KZqcfnbcjdLMQRyT2QlVClkvTKa/z VhnS2hSp7QL5v3XajVpQNUs4ANOPZew/tMdswP/Am1qtUXPMh+OiPlRZYKykmyVMEi50 sFUkzOvnJNQHfCHO2vfrBUUKh4R2vL1UdNS9omIpwACdfCZIqS4OEhhqQfE9gtoUp7h2 stEGXgIgv7Le5sWSvek2qrfZTzafhduHVwpJLls4Z/yNafHf9PRjam4fSYVwlZ9Emauv Nv872+53ZN6owoUQs6CXDHp/iRs6SngK3zbWgyIDrnFqBTDQEM3oEdHCNL4D1HoK0R1T WsZQ== 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=ABNW8Ajn1XgrsC/inutkCGrucotXNrHK51/jmxoTuLzxxSFtZ1wXks9pAbuNqKCSu0 DaFHiiUVMZbkUR6kTvU7UgtKttFg433taCjZJhGnpAa+UajfhC+ZiftE2ueCvqhCNrbq O2zQQMJ9wnhoEfqXXjbrZV5qNgc2AT2OAwE6Bqnkc1D/OATsMRFo9fnf3WInTDjzD0QT IMiLvDCVm1g71WMhZlU2XLZLJix1AyFaeDGWClSnh/8mcgVhY8ublT59WW4J9gBaHS2F 3akQ/PZAkw3BzUJ0c6QDifu7kqhgoFYvDublj8ACBzSY29YUgTfAujR17VRV2qOvTLar QZGA== 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 i15-20020a50cfcf000000b00418c2b5bdcfsi3198398edk.177.2022.04.02.03.50.42; Sat, 02 Apr 2022 03:51:42 -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 S1343529AbiDAKaC (ORCPT + 99 others); Fri, 1 Apr 2022 06:30:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343579AbiDAK35 (ORCPT ); Fri, 1 Apr 2022 06:29:57 -0400 Received: from mxout01.lancloud.ru (mxout01.lancloud.ru [45.84.86.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9ACB26E740 for ; Fri, 1 Apr 2022 03:28:05 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout01.lancloud.ru 894C720CFC5D 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 13:27:53 +0300 Message-ID: <20220401102757.3960551-4-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 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