Received: by 2002:a05:7412:d024:b0:f9:90c9:de9f with SMTP id bd36csp124224rdb; Wed, 20 Dec 2023 07:54:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfrVemA2IgSDjdx2+IpTX9iDloAL4JPwpBKe2Jjw/k7vHK2pRiadaeOdkDQld5ED7vnuW4 X-Received: by 2002:a05:6102:c4b:b0:466:91ae:1157 with SMTP id y11-20020a0561020c4b00b0046691ae1157mr3867049vss.33.1703087664214; Wed, 20 Dec 2023 07:54:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703087664; cv=none; d=google.com; s=arc-20160816; b=y/4OT82EK8cr1z58bX28zvyyOEs6es2Pt1OGTJmAN7mmZ5axsZEYe4Rs6CHJOTVNfa tPKMLI5RG/hvNjbAgGFpx/xex1Rt7smvhJsyJBBKjzZc1LiVVKNxl3tbKxaPmiFjQ073 Nlu2w4nN7AiXib1bRXmNBrpNilIaUUG/OzLyOTTaoNEumuN1W+nUBVtM4kA68LzETwU1 HTVvXA++KviL4aXDWMj3+rEbwgrK8rIeEMMjpx45Z34QQWsVqE+qhPFyMEpEud4t9cS4 TmNlZIE261um3ju9xYBIcKtXPLsApA60OwmHWRfP1zE0VJyirc4q7nz7n91gLIpbStjY POtw== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=F5sbvrgTVmhtel2oNQz7C7epZ+XvoS2wY5UmZpkNQgQ=; fh=jtkMVljxaSSnm+wRWxFZHf/UR4p8LFQ8rZaEaUeBMWE=; b=h9enDYncfQABx91LxLqXHqsPgK1kgK+XNIV5h3hVjZNSov5md8545smc9ejY5UDa60 yyivWccrnmxN23AHNlbys/JEbje2R7lowqjolElLp2vTezfdLp77UgMfuHZIRtTuQ1OG K2Ze4dA3AfNMnvPN3AjGo+lal5MeLxQ09nkCodf2i7UPl0ET0m2uriSUZ6E7yQZ1qg1V blTWmvyhCSvj942C0BE+9M525aZ7Kbi5TCtQ0ZyXQL5HHQdxc6m0vhBjpGUWMPEfNYRj F6hIAhIuB1N9MWYB0QrlMKwQTDsc3hHV6yKIGx9aZ53tuQ4JYvjorYG4zrSVDbxA1ep4 /+BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=bRyOBBcJ; spf=pass (google.com: domain of linux-kernel+bounces-7207-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7207-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u5-20020a05622a17c500b00423dfaba41asi29621833qtk.644.2023.12.20.07.54.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 07:54:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7207-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=bRyOBBcJ; spf=pass (google.com: domain of linux-kernel+bounces-7207-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7207-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EC5541C2452D for ; Wed, 20 Dec 2023 15:54:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DA6D4642F; Wed, 20 Dec 2023 15:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="bRyOBBcJ" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 C74464778E; Wed, 20 Dec 2023 15:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensource.cirrus.com Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BKFAj8b027175; Wed, 20 Dec 2023 09:52:58 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=PODMain02222019; bh=F 5sbvrgTVmhtel2oNQz7C7epZ+XvoS2wY5UmZpkNQgQ=; b=bRyOBBcJdMaJCN36C Iki9b/LW49vdlbV2Ec21znP58uQbtvZci8ndmkXqeha3S/hCIodPB2OKqw9eMxHJ gOnyyxRoYgv+RsjHt3RzcNRG4JeI9E+vU0nfWRfTKqZyJc3syvH700CQZ91yJu1h iq0laukD8sldBRtr8tlkym30N4A/pAZM03Tj6wbttgsAwtOOHr9SYsOXkHP78nqI hBZUUC7XVGpFii0Vs5tJXlv4/fM0/m7JUeYmiHT3u3qreYGJFK0aSlmtr/Iwnlyc YohUPaGyIFsqgBzq6Xr3LoWFZ3xYy8ayN3FOaVTQNF4L6FaYwmiU9nq7IShAqOw+ u8aiQ== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3v196ndmxe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 09:52:57 -0600 (CST) Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 20 Dec 2023 15:52:56 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.40 via Frontend Transport; Wed, 20 Dec 2023 15:52:56 +0000 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.82]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 4B00B11D1; Wed, 20 Dec 2023 15:52:56 +0000 (UTC) From: Richard Fitzgerald To: , , CC: , , , , "Richard Fitzgerald" Subject: [PATCH] kunit: Protect string comparisons against NULL Date: Wed, 20 Dec 2023 15:52:56 +0000 Message-ID: <20231220155256.407974-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: CfJWcoIQ1BfjL_JfiueeI0Y0Zpicel4K X-Proofpoint-GUID: CfJWcoIQ1BfjL_JfiueeI0Y0Zpicel4K X-Proofpoint-Spam-Reason: safe Add NULL checks to KUNIT_BINARY_STR_ASSERTION() so that it will fail cleanly if either pointer is NULL, instead of causing a NULL pointer dereference in the strcmp(). A test failure could be that a string is unexpectedly NULL. This could be trapped by KUNIT_ASSERT_NOT_NULL() but that would terminate the test at that point. It's preferable that the KUNIT_EXPECT_STR*() macros can handle NULL pointers as a failure. Signed-off-by: Richard Fitzgerald --- include/kunit/test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index b163b9984b33..c2ce379c329b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -758,7 +758,7 @@ do { \ .right_text = #right, \ }; \ \ - if (likely(strcmp(__left, __right) op 0)) \ + if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \ break; \ \ \ -- 2.30.2