Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp151851lqo; Thu, 16 May 2024 02:04:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4tF5hsKQt0Ume51qF+2uLnIsvVXecOvVQqFoXmKFE7/lbIw0ps6LgO0SK1ugLAQsS7mHxhP2g1IaSKXHJzXPYjdFZHWXNIyQCOyw1Kw== X-Google-Smtp-Source: AGHT+IEdC5ExAyxsOoyMyCFvItki4YNbm4xaRTdMJU3yfHVWetoK7Cl7Ylg39HdtHlzIh8g3C7St X-Received: by 2002:a17:906:37d9:b0:a5a:3ea6:689e with SMTP id a640c23a62f3a-a5a3ea6692amr990692266b.71.1715850271120; Thu, 16 May 2024 02:04:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715850271; cv=pass; d=google.com; s=arc-20160816; b=AHDC60n5/BeqYyn2ZQOi222FEx2Q3V/hfYRLRv2a43gpm6cU6tThDzRoCi66vBjJmZ 9fjXXEGmnYnnf9UB4g5HTYVwqsHM40IOF1yoiBTaCrlZbwS2g+dHUxRwsWaVuCR0cStL KIr4vpag1oJJ08aq2EtJ7uW3PGSnVSvqUR6xNofVxmD3JthMk7mLXfORL2H7K94jJEwE j8RtXB2btU0lg1dQdl3g4oGKTOcg1Legwu1foNct749jR5DQxfhsTcK81mwryVeeoKsP EQUJbNlj1FaALZhbY8d7ejtZcrsfDydtSBVX/Oz0QQSHEwIfBL9Bfs9NsNKMn/LCd36H 0Sjg== 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=y09fMZFZdwB255OsUc6Q3OkYP0rKNvhlGoEON3cztVE=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=UHDifpkFZ6bJsQCpgGYiK0k2pya5ljw06aWo7on7/jLzrwS9lm0/32DUj67czlriJ7 9QHXCwGDEn5nS8pRt8QvtrKkQ8pxz/pp0fFiwNeALKh/VZ3Cg2mhRkfTzBJCWS/W8H9k qxSvKsaoLN72Lu2TRLarrWfRzQ2uyjlVyT8zQWJvp4D2HMwxKXkWhReLYZX+1t1H7zsc tFSRotn+5FYiGk0mEA0SFkCBB5lRsZeqNMT3rXjlS/tInFcjRTrfHtHT0LZlLAArHopQ DzhMwxMEQ+9qwKQJnHnAigZz+ScTSFyHEquSYrR6ZdAUp5vZ3/VGAhX3orbSGUzr4igu Xwkg==; 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-4696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4696-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a179463basi809817466b.126.2024.05.16.02.04.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 02:04:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4696-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D58DB1F21A42 for ; Thu, 16 May 2024 09:04:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AF2D143872; Thu, 16 May 2024 09:03:53 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 94653143757 for ; Thu, 16 May 2024 09:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715850233; cv=none; b=HH8HtTnP6kVf4waw86e0w+sGT92XdxYzklfRqIjAgraZJlWukMsH+SoG0VKrkuGNu+OjPIVfBR4LX9fQTZk8kM/uGL046oyu52DWp1V5+3GomtVYoZ38z0mBUIaO+eRekw+AdfL2Hd2A92JrnfdrfPYCZaMCrOpr+CNxu4HXPrU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715850233; c=relaxed/simple; bh=wBKaBDtRcPjNoMraWYoXvslQgUVGW3mNUPea6jugRso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n0qwA3kg0B5Qtk3glesYChZXyQDZxvGntVCrMYkXOUKobRBmsSPEi8mQ1mb0BJu6IHj3OJmqm8pFbjEsVl5iiu2Ap/4jV9Ah9BO3ifKTULpKCTCnCX7WtcrpsfKtXcnbb4DeKUWaRuTSEGWFV9i362/VqCnsP+ZtZOVRUm1zzFw= 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.197 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 8D9A71C001B; Thu, 16 May 2024 09:03:44 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ 12/15] mgmt-tester: Fix non-nul-terminated string Date: Thu, 16 May 2024 11:03:16 +0200 Message-ID: <20240516090340.61417-13-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240516090340.61417-1-hadess@hadess.net> References: <20240516090340.61417-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 Error: STRING_NULL (CWE-170): [#def59] [important] bluez-5.75/tools/mgmt-tester.c:12670:2: string_null_source: Function "vhci_read_devcd" does not terminate string "buf". bluez-5.75/tools/mgmt-tester.c:12677:2: string_null: Passing unterminated string "buf" to "strtok_r", which expects a null-terminated string. 12675| 12676| /* Verify if all devcoredump header fields are present */ 12677|-> line = strtok_r(buf, delim, &saveptr); 12678| while (strlen(test->expect_dump_data[i])) { 12679| if (!line || strcmp(line, test->expect_dump_data[i])) { --- tools/mgmt-tester.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index 8a4fbc2eb6a6..8076ec105ebb 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -12656,18 +12656,22 @@ static void verify_devcd(void *user_data) struct test_data *data = tester_get_data(); const struct generic_data *test = data->test_data; struct vhci *vhci = hciemu_get_vhci(data->hciemu); - char buf[MAX_COREDUMP_BUF_LEN] = {0}; + char buf[MAX_COREDUMP_BUF_LEN + 1] = {0}; + int read; char delim[] = "\n"; char *line; char *saveptr; int i = 0; /* Read the generated devcoredump file */ - if (vhci_read_devcd(vhci, buf, sizeof(buf)) <= 0) { + read = vhci_read_devcd(vhci, buf, MAX_COREDUMP_BUF_LEN); + if (read <= 0) { tester_warn("Unable to read devcoredump"); tester_test_failed(); return; } + /* Make sure buf is nul-terminated */ + buf[read + 1] = '\0'; /* Verify if all devcoredump header fields are present */ line = strtok_r(buf, delim, &saveptr); -- 2.44.0