Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1357136lqb; Thu, 30 May 2024 08:01:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWAekUumVVWgSJrDUByn5NaYGbxVxxA45VuNeLRPWvSIObo4OrACClSJ6MEiBbesQuHgvbjUVLpj9grIjMBf9FIB6DdThEqADxj3l1XKw== X-Google-Smtp-Source: AGHT+IFhsb0TO3xmELITiXbxhCZUnAKhES646m29CiucVmDr6E5o0DDZHVzdKPiP/KFAuSYq4So7 X-Received: by 2002:a17:903:2344:b0:1f4:b7ff:ac4f with SMTP id d9443c01a7336-1f61973a1e6mr24215585ad.50.1717081280693; Thu, 30 May 2024 08:01:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717081280; cv=pass; d=google.com; s=arc-20160816; b=o7W56sAJ6H3rCud1aXBJm85tvPeybs+FhBBRDG9U+97xqSN+Jd81DLIWXctbkMrPem ILat6DyZp/rcRsrm8kN3IRr4/qSPMzInjt+7Tc2xD4z/2FAaGmUtxUwM6ZV5REecRS37 YpDgM7PVhapwoKakft5sawYAu1nHQ4oC3lFIup+eijDVOqv0n9DuKZ4JtHvYm7pAzIEo uA+veahbWmfQ/Iq9y7C2rC27NgM7fBXpvL39G2t7zSS4my6bH38wmyKeIX2ctzHeQbcb /dFIeJyW8zjVleGfaGjkrymz+EWgmV+zuxCvyzoacj/QiRgeRBl5U2RtrAIEyQRaDOJT 8EJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=rLuwEO3euoAjs04PvFN75HIOu7W+vNCAJ03BvsraRYI=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=DM/ceCJMbFIHyNfQvW2cQPq93vnICexRIAKjeXfEr1nb1jf7y7M7J0IsliaO4O+rrX 7h0glpZynTy3F46xSaYFe1+DCsSC6bcGQe5S2f2IjDWk/5Pt856f78RAYmJjyxdzddM1 30SbCuVLZky4QcMRACXBhStsNSWZ1o1itSJlfbzHUB6aJDNk70b7gnzZsziwLgEF3kry IZ9zP+BOBsCJZ+KDbnuSthrmRf4uOYfh/obxA7ZGx2HcoAyExJ4GBNhb9gqLN8KJmojQ 9Eh32iphD+COmWyTe+NsyXk2U2un74USBb8NcO6/JEiC4l8ILszvZQDYw0bSKe86MeOI oKQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-5036-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5036-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c789526si600605ad.74.2024.05.30.08.01.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 08:01:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-5036-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-5036-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5036-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D75D3B22FE7 for ; Thu, 30 May 2024 15:01:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1DBE17D8B2; Thu, 30 May 2024 15:01:02 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AE5C1E89A for ; Thu, 30 May 2024 15:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717081262; cv=none; b=RTwcmjmfKXculQj5qrYzu0cAzIuvXAysIeIiiRTu4k05uiiDcHRF+sz+SDL/zQWE9d4HBvwyAOHwlDOWM2eZ7xEa0fnlCft8KSMYUkVj6MAuYEMhxKqapMZpM7OKjkWAZQSeZ5/zfmSivIeyqyi1J3cW1XSho1Ey9248xEPxsBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717081262; c=relaxed/simple; bh=YdhSO3QIYKxHiPHW4z302UhfJABUeFRJ4d58sXWWM6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ncaMSI0s4eawBXnUFiNJYCSBcEIN4gge8FHvNNZcDHCswc0tTWIKA/oUdwQDGPKK4b6FPA6WYcu2TzZRFfg0QXGah9cV8d26ZOPoJrkvG776bm1zVuXzGhGUQ8SYIkjiGpDGFROGOBkbuWcOTasJhZ6vK/unYNExtyr3J6TFbf8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id 938CA20012; Thu, 30 May 2024 15:00:58 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ 3/9] l2test: Add missing error checking Date: Thu, 30 May 2024 16:57:57 +0200 Message-ID: <20240530150057.444585-4-hadess@hadess.net> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240530150057.444585-1-hadess@hadess.net> References: <20240530150057.444585-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net send() might fail and return a negative len, catch that to avoid advancing the send buffer in the wrong direction and causing all sorts of problems. 977|-> len = send(sk, buf + sent, buflen, 0); 978| 979| sent += len; --- tools/l2test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/l2test.c b/tools/l2test.c index 011a68c3781e..7b6c36e165da 100644 --- a/tools/l2test.c +++ b/tools/l2test.c @@ -975,6 +975,11 @@ static void do_send(int sk) buflen = (size > omtu) ? omtu : size; len = send(sk, buf + sent, buflen, 0); + if (len < 0) { + syslog(LOG_ERR, "Send failed: %s (%d)", + strerror(errno), errno); + exit(1); + } sent += len; size -= len; -- 2.45.1