From patchwork Mon Oct 6 20:41:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4468 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:7505:b0:72f:f16c:e055 with SMTP id r5csp7094395mai; Mon, 6 Oct 2025 13:41:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW52OQ2XyMqf2q/+ZQEwgYPQJUfz20pLSMrebMutHo+RtoHsTkbTAOTlNKeKiOOalNLDbA68rgH1Ik=@openvpn.net X-Google-Smtp-Source: AGHT+IFa9pMqGGD9DpVi6j8rw9UzlU6GsU1h+6wRNifzbqi9Z6m8ZL94Mo2arNphreUC/9W1dWXQ X-Received: by 2002:a05:6871:808:b0:36d:287c:694f with SMTP id 586e51a60fabf-3b0f988a726mr7777314fac.30.1759783297785; Mon, 06 Oct 2025 13:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1759783297; cv=none; d=google.com; s=arc-20240605; b=Sf2Ii1qS2O041sC8/ozbaOzDL0UmXHDAZUR7afeBXwREys3/LHZtGztU6Liv5PRxo/ JTA4CJir5fpF3L/mcDa3SbQTZH0Q7TV72Rh4jPH72XR1LI1D16nTJETMnv/sL4KXc66g 2uOe3jAcLwVQqKlMiuWxIpzGj0prRCYsGkmyrKgmbn+Tlg3FhIPgF8pmnL2yecnm1icN GDqkgqBjFJz9QqZ1zRfmXFXpefadVcqsX9kgOu/2TqPqhsIHypM2cRg7mUWv3Jp4nKO1 Xz/eETLT9dbCBkrGYoE9L2TjF1cYBvsPH7gW0TCiAhGx7voQ2IrG1YMvp/ROJnfZBHWH wzeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=q9bsRvV/BnDNVV5w8isZQHgrHc0xT+3G77hNGKCY+A4=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Od5EQBWfWFO7SnWuqU1707ByxsRBeW4G2cUKrV9mz0Bmri7ZRV+I1SRcoxwELn0f08 BE5C9CCiZuvZWMUBRBFw9Mnw5iubPBKLq5ERQ4H/4LyqUzDPxvJtpZpDtQQV7/vnIhtQ Mes9niESwp7dOThiMjx94PXG8cARbrj0DQJX/V/z+hNRQMZZM4b/YgbYgqeIWqS4EkoH fQ2nb+lbWtZ5yyze5zsYUg7nb18Yp2wCOwG49b1X5IZSS5c/NIj23d8mBql3RAA1shWf f/4Y8W7skBiMDXJ2CMq4l2+foTx8ODCUg1jn3hPt2ocu6BFFj4qAt7arJIe/fN3kbLNH MFLg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=WWFzAUdB; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=gda+3sHP; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=AmdcF92Q; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-3be8957b1d2si158521fac.83.2025.10.06.13.41.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Oct 2025 13:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=WWFzAUdB; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=gda+3sHP; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=AmdcF92Q; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=q9bsRvV/BnDNVV5w8isZQHgrHc0xT+3G77hNGKCY+A4=; b=WWFzAUdBS0ZKaI8Vt/4lbaofg1 N6q4H+5Rbz5VpQOiuVOE6ytGnEUqOvwi+3nzc+0eaM4NXbgCyKWgMP+W6osRnvU3Iz75Pzur0ETOx bbVRb4pla0pGqzMLIJmm73PHyMQgNfA/H6sYRkQ3MWh6gnp0jPPHzCUU4RM9XU8T4jpc=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v5s1W-0005Xc-Cp; Mon, 06 Oct 2025 20:41:34 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v5s1U-0005XW-4H for openvpn-devel@lists.sourceforge.net; Mon, 06 Oct 2025 20:41:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=31+HyC//auTQ5MLQ5ZTOIhBFU1r3w8LBsdsn4S0I2K8=; b=gda+3sHPPtAvRVStj6ZILtR5ml o1qsveFQyWEuuNQZbikK6rvzSEDwzQjfyxeyX6niOG7zi758kvYnaYT46wByvw/HGlgTC36mnqXnA PwH+cWD7x0hNUq5oPOuGNaI1E3QhFjeaRdB2Fi2fuH2z7hbPfR0KrLFU5ls2iQSuWF6M=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=31+HyC//auTQ5MLQ5ZTOIhBFU1r3w8LBsdsn4S0I2K8=; b=AmdcF92Qx91LueDEMyYDLixw20 aE08NWA3JaBL4cc/XvLzWxXDVMdcVhDR+8VXEU6Zaq6sPPUBLipcappGfcfMTs6QjuN7bAy9Qm5Dj MCK4LLrb9MT+dUwrEYrsJ7DhxudMThGRs30IszeAGliHEQh0bUQElgjSK51N9wN+BPF0=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1v5s1S-0002Jm-Op for openvpn-devel@lists.sourceforge.net; Mon, 06 Oct 2025 20:41:32 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 596KfIlW026261 for ; Mon, 6 Oct 2025 22:41:18 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 596KfIhf026260 for openvpn-devel@lists.sourceforge.net; Mon, 6 Oct 2025 22:41:18 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 6 Oct 2025 22:41:09 +0200 Message-ID: <20251006204118.26237-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld Replace some assert_true calls with more specific assertions. This should improve reporting in case of problems and also just makes the code nicer. Change-Id: Ia2f374476c87855bba6c0f9d3e2f28a5fe62a152 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/open [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1v5s1S-0002Jm-Op Subject: [Openvpn-devel] [PATCH v3] Review CMocka assertion usage X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1845266531269935263?= X-GMAIL-MSGID: =?utf-8?q?1845266531269935263?= From: Frank Lichtenheld Replace some assert_true calls with more specific assertions. This should improve reporting in case of problems and also just makes the code nicer. Change-Id: Ia2f374476c87855bba6c0f9d3e2f28a5fe62a152 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1141 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1141 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/tests/unit_tests/openvpn/test_auth_token.c index a2a10ea..68e4693 100644 --- a/tests/unit_tests/openvpn/test_auth_token.c +++ b/tests/unit_tests/openvpn/test_auth_token.c @@ -286,9 +286,9 @@ strcpy(ctx->up.password, ctx->multi.auth_token); assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK); - assert_int_not_equal(0, memcmp(ctx->multi.auth_token_initial + strlen(SESSION_ID_PREFIX), - token_sessiona + strlen(SESSION_ID_PREFIX), - AUTH_TOKEN_SESSION_ID_BASE64_LEN)); + assert_memory_not_equal(ctx->multi.auth_token_initial + strlen(SESSION_ID_PREFIX), + token_sessiona + strlen(SESSION_ID_PREFIX), + AUTH_TOKEN_SESSION_ID_BASE64_LEN); /* The first token is valid but should trigger the invalid response since * the session id is not the same */ diff --git a/tests/unit_tests/openvpn/test_packet_id.c b/tests/unit_tests/openvpn/test_packet_id.c index 0eacbab..ec71bc3 100644 --- a/tests/unit_tests/openvpn/test_packet_id.c +++ b/tests/unit_tests/openvpn/test_packet_id.c @@ -82,9 +82,9 @@ now = 5010; assert_true(packet_id_write(&data->pis, &data->test_buf, false, false)); - assert_true(data->pis.id == 1); - assert_true(data->test_buf_data.buf_id == htonl(1)); - assert_true(data->test_buf_data.buf_time == 0); + assert_int_equal(data->pis.id, 1); + assert_int_equal(data->test_buf_data.buf_id, htonl(1)); + assert_int_equal(data->test_buf_data.buf_time, 0); } static void @@ -96,8 +96,8 @@ assert_true(packet_id_write(&data->pis, &data->test_buf, true, false)); assert_int_equal(data->pis.id, 1); assert_int_equal(data->pis.time, now); - assert_true(data->test_buf_data.buf_id == htonl(1)); - assert_true(data->test_buf_data.buf_time == htonl((uint32_t)now)); + assert_int_equal(data->test_buf_data.buf_id, htonl(1)); + assert_int_equal(data->test_buf_data.buf_time, htonl((uint32_t)now)); } static void @@ -108,9 +108,9 @@ data->test_buf.offset = sizeof(packet_id_type); now = 5010; assert_true(packet_id_write(&data->pis, &data->test_buf, false, true)); - assert_true(data->pis.id == 1); - assert_true(data->test_buf_data.buf_id == htonl(1)); - assert_true(data->test_buf_data.buf_time == 0); + assert_int_equal(data->pis.id, 1); + assert_int_equal(data->test_buf_data.buf_id, htonl(1)); + assert_int_equal(data->test_buf_data.buf_time, 0); } static void @@ -123,8 +123,8 @@ assert_true(packet_id_write(&data->pis, &data->test_buf, true, true)); assert_int_equal(data->pis.id, 1); assert_int_equal(data->pis.time, now); - assert_true(data->test_buf_data.buf_id == htonl(1)); - assert_true(data->test_buf_data.buf_time == htonl((uint32_t)now)); + assert_int_equal(data->test_buf_data.buf_id, htonl(1)); + assert_int_equal(data->test_buf_data.buf_time, htonl((uint32_t)now)); } static void @@ -156,8 +156,8 @@ assert_int_equal(data->pis.id, 1); assert_int_equal(data->pis.time, now); - assert_true(data->test_buf_data.buf_id == htonl(1)); - assert_true(data->test_buf_data.buf_time == htonl((uint32_t)now)); + assert_int_equal(data->test_buf_data.buf_id, htonl(1)); + assert_int_equal(data->test_buf_data.buf_time, htonl((uint32_t)now)); } static void diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/openvpn/test_provider.c index 463b394..48adb96 100644 --- a/tests/unit_tests/openvpn/test_provider.c +++ b/tests/unit_tests/openvpn/test_provider.c @@ -287,9 +287,9 @@ for (size_t i = 0; i < _countof(pubkeys); i++) { pubkey = load_pubkey(pubkeys[i]); - assert_true(pubkey != NULL); + assert_non_null(pubkey); EVP_PKEY *privkey = xkey_load_management_key(NULL, pubkey); - assert_true(privkey != NULL); + assert_non_null(privkey); management->settings.flags = MF_EXTERNAL_KEY | MF_EXTERNAL_KEY_PSSPAD; @@ -384,11 +384,11 @@ for (size_t i = 0; i < _countof(pubkeys); i++) { pubkey = load_pubkey(pubkeys[i]); - assert_true(pubkey != NULL); + assert_non_null(pubkey); EVP_PKEY *privkey = xkey_load_generic_key(NULL, (void *)dummy, pubkey, xkey_sign, xkey_free); - assert_true(privkey != NULL); + assert_non_null(privkey); xkey_sign_called = 0; xkey_free_called = 0; diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c index 950ce26..6fe64b2 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -487,9 +487,8 @@ assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, &unwrap_metadata, wrapped_client_key, &ctx->server_keys.decrypt)); - assert_true(0 - == memcmp(ctx->client_key2.keys, unwrapped_client_key2.keys, - sizeof(ctx->client_key2.keys))); + assert_memory_equal(ctx->client_key2.keys, unwrapped_client_key2.keys, + sizeof(ctx->client_key2.keys)); } /** @@ -511,9 +510,8 @@ assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, &unwrap_metadata, ctx->wkc, &ctx->server_keys.decrypt)); - assert_true(0 - == memcmp(ctx->client_key2.keys, unwrapped_client_key2.keys, - sizeof(ctx->client_key2.keys))); + assert_memory_equal(ctx->client_key2.keys, unwrapped_client_key2.keys, + sizeof(ctx->client_key2.keys)); assert_true(buf_equal(&ctx->metadata, &unwrap_metadata)); struct tls_wrap_ctx wrap_ctx = { @@ -563,8 +561,8 @@ ctx->wkc, &ctx->server_keys.decrypt)); const struct key2 zero = { 0 }; - assert_true(0 == memcmp(&unwrapped_client_key2, &zero, sizeof(zero))); - assert_true(0 == BLEN(&ctx->unwrapped_metadata)); + assert_memory_equal(&unwrapped_client_key2, &zero, sizeof(zero)); + assert_int_equal(0, BLEN(&ctx->unwrapped_metadata)); } /** @@ -587,8 +585,8 @@ ctx->wkc, &ctx->server_keys.decrypt)); const struct key2 zero = { 0 }; - assert_true(0 == memcmp(&unwrapped_client_key2, &zero, sizeof(zero))); - assert_true(0 == BLEN(&ctx->unwrapped_metadata)); + assert_memory_equal(&unwrapped_client_key2, &zero, sizeof(zero)); + assert_int_equal(0, BLEN(&ctx->unwrapped_metadata)); } static void