Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4963568rdb; Fri, 29 Dec 2023 23:18:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOEKQorvLj8iLy7YwVmWMOf4NSoGICfV5vbGvvy3DrnAvu23JXfZvZC47ZmVjJM/S2f8Ba X-Received: by 2002:a0c:e790:0:b0:67f:de61:a8ac with SMTP id x16-20020a0ce790000000b0067fde61a8acmr10466686qvn.107.1703920681694; Fri, 29 Dec 2023 23:18:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703920681; cv=none; d=google.com; s=arc-20160816; b=HDn5HTyFN+thXqoRnUpNqqx2ozDbhaq2pAaNTf29J0Wlt52SnDwBd3CHQW5FrUCsUx vtIvaHdCFm5B2CTBeR9ce4DO2eZb7+GrwBxvXlNR6gEiQotRFuGH+joEEuGSC5Xar8I0 poYRss56ycYSz9S5kg2JeCiN6f2xOjg5DymixcSDH6AFFe9LHpSZUzp2HTwncEZAQmSj PgqjBpPBkNyAhDkcp5JriyevQJI4RyL5fAetZx1iKkuaPeWo9wsMOcPicrTJxFiybWPo CFjo8sN67USlp3Ynh4ruEBjPI8T/mvyzDnVSImC8LQZ7BAsl7xVg+YLZWQgLvKmIXjyr e5zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=R0rZUqsX9cP6xWsyP0B7nxsGXNl1o5DLdNbd/fuHH6A=; fh=oOhgVbM8m3aJGRSnTTM6KTF3eVQYf5X2ybF1CBlpGdA=; b=fhMw3Clo3HhDbBQh2YStMqLe12oNNbd94OCVQ3k2EHQGndPKSpkK5yjFNexfMnPKRI ZCAITW1wAo+eFm9uJDAmZLtnsK0M481q7mHgafMCTK+YXO9Vrugry0GRO8FDvPR05T/6 AU502jPCABYAUxG8ADS3hsflG+SZm88XYpcdH6pRfmgFfDqrjyCMfxLIchXhpVZQjgdy JUXZ4Bh3UIPoS8tlGViHoIk3cnTiLfYOkWQ1gRAAV5G21VOWYO0v2pHXw28hvaORkCnq 2e4yB6FfQ69OL8Q3cmz546xTE+VlLWo1p8yMRs1R5zgZpmrYqA1e/Gjw8xXULLY8rHEy ROzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hE5CErlJ; spf=pass (google.com: domain of linux-kernel+bounces-13350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13350-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.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 z5-20020a0cf245000000b0067f2b0d0c60si20512228qvl.281.2023.12.29.23.18.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 23:18:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13350-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=@collabora.com header.s=mail header.b=hE5CErlJ; spf=pass (google.com: domain of linux-kernel+bounces-13350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13350-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.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 5796B1C20B5F for ; Sat, 30 Dec 2023 07:18:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1A511FCF; Sat, 30 Dec 2023 07:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="hE5CErlJ" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (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 B2BE24404; Sat, 30 Dec 2023 07:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1703920671; bh=d1iZc91LabcnMVqjWAlFYm0XHTmeSnEeDR2JG77Ywrw=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=hE5CErlJG3Eniyw3kJTkZPVa7omSD2Ig6+aA5VgrEy3z0vkq4Ez7Rbo2OxxUTcXkb 4JFwL5vUqoXPacoLYcd/TycKljtJnf7pB5oF6TqAujgGPYS/50H9yXmXLOmSg7tE+S mYxq09LroA5O8pJ3q8NT/cAEpaT2rVjychExSmJUjEy6wWjIFNiHFCoWLr/W540mk9 FcZug0qTq2zLB1pAvSBlwLNCBN8/4GlGFMQScI7Ez9ErGVQupmcagQCqg7TaurVzEk jMbsBzvRakwt03Z3z+dFDXAOJl9UWTgPlLdUe99dmRCEjY8J9JV1gfmv000owWA5dP PptrH5ANUBV0g== Received: from [100.96.234.34] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id ABBAF37811F1; Sat, 30 Dec 2023 07:17:46 +0000 (UTC) Message-ID: Date: Sat, 30 Dec 2023 12:17:49 +0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Subject: Re: [PATCH] kunit: Protect string comparisons against NULL Content-Language: en-US To: Richard Fitzgerald , brendan.higgins@linux.dev, davidgow@google.com, rmoar@google.com References: <20231220155256.407974-1-rf@opensource.cirrus.com> From: Muhammad Usama Anjum In-Reply-To: <20231220155256.407974-1-rf@opensource.cirrus.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/20/23 8:52 PM, Richard Fitzgerald wrote: > 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 Reviewed-by: Muhammad Usama Anjum > --- > 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; \ > \ > \ -- BR, Muhammad Usama Anjum