From patchwork Tue Jun 13 18:34:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1794622 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Xwp9Wkp3; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qgcfv1XsMz20Vx for ; Wed, 14 Jun 2023 04:35:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CADE46112C; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CADE46112C Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Xwp9Wkp3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tFXmZ7JMPXkU; Tue, 13 Jun 2023 18:34:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 53BE3610FF; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 53BE3610FF Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3346FC0092; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 417EEC0029 for ; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 182D582183 for ; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 182D582183 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Xwp9Wkp3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id brgH1j9uDrYI for ; Tue, 13 Jun 2023 18:34:54 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 21633820DC Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by smtp1.osuosl.org (Postfix) with ESMTPS id 21633820DC for ; Tue, 13 Jun 2023 18:34:54 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b3d8aa2c17so13468005ad.3 for ; Tue, 13 Jun 2023 11:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681293; x=1689273293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aRi1AE/dD+xltBfFp+HP4yaUtcYQGpi+pNNwXiOgplw=; b=Xwp9Wkp3Es0hla5jxBBAuKzt8r/w/6JUFpYHeaehz2f7fKoTFpVRPxEA5AslWiLpPg 7/PQCA9x19TlfuNibu0GFiv/r1LLHCA/1T1/7PCQbWw2s6UQ3NlWoUpzpd8yMdVambal Funt1RJOBdrvPke7W99AyFca57hoLp5I4bMqRK5ghvEewxE4jn5EaLJqduCQqSxuFoOz zJusziD0V/Z7KtUYZIMsJwPZVj6KTujNEjXx4xOp97l019iY8oV+czffW7b2UQgpRbsp 6SlZEXi9Na0EDkRzmIjWNaBFfa0zPfxVd4dNLpx+wNq16c1S58qA/9UkATm8L876IqvE /e+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681293; x=1689273293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aRi1AE/dD+xltBfFp+HP4yaUtcYQGpi+pNNwXiOgplw=; b=Ghug+NcGog+P/Xgha/Kvbqq4tm08+/wDMRPIGvi+ZfBuH7YGXOhvolv/T32VgGZKLt e+FiHxHi35C9f2fzyf8V6wUJs81EY0R4aUKd38Eqxx3GpvqfgtQjkeQ6F7Y5btS/Xcpi ISMms/KNLjm54sjXe1Ng3X9brNbuZo2n12br+dC9ZdRdDSXvkSWs7vbi/4Rr7Y+KKGVw z/agpBtZsOEci1PlqvUgciq1HuALYQ3R5MGN4erJS2H/dZ14XVzGxdHnQ0aR7e5PP8yr MTCSXsqhZ4Z3iZN/DvS5sqRPv0vwP2u3o4xqYNGhjtsb4/4kVYKQto/FMcc9xio7KWuH 4fiw== X-Gm-Message-State: AC+VfDy91CsTwsRZp6uzzUD5i46k6iPwauGrzo1XH3AjhP1yE0kOjadv 7nc5R0U0zrjIlpMAcyXfkibwGDtX9erAlQ== X-Google-Smtp-Source: ACHHUZ59fe6P1UZfvNhZ5HaslxAHjFHljfl4mZvD3fPiqqWsc9dPoRNJsIrKvtF9QxeEVH56NAyPaA== X-Received: by 2002:a17:902:c20b:b0:1af:d9d2:a234 with SMTP id 11-20020a170902c20b00b001afd9d2a234mr9570061pll.3.1686681293107; Tue, 13 Jun 2023 11:34:53 -0700 (PDT) Received: from JRT-PC.lan ([103.252.200.22]) by smtp.gmail.com with ESMTPSA id u3-20020a170902e80300b001b04aee1f99sm10531125plg.228.2023.06.13.11.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:52 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:38 +0800 Message-Id: <20230613183443.31540-4-jamestiotio@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230613183443.31540-1-jamestiotio@gmail.com> References: <20230613183443.31540-1-jamestiotio@gmail.com> MIME-Version: 1.0 Cc: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 3/8] shash, simap, smap: Add assertions to `*_count` functions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds assertions in the functions `shash_count`, `simap_count`, and `smap_count` to ensure that the corresponding input struct pointer is not NULL. This ensures that if the return values of `shash_sort`, `simap_sort`, or `smap_sort` are NULL, then the following for loops would not attempt to access the pointer, which might result in segmentation faults or undefined behavior. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman Acked-by: Eelco Chaudron --- lib/shash.c | 2 ++ lib/simap.c | 2 ++ lib/smap.c | 1 + 3 files changed, 5 insertions(+) diff --git a/lib/shash.c b/lib/shash.c index a7b2c6458..2bfc8eb50 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -17,6 +17,7 @@ #include #include "openvswitch/shash.h" #include "hash.h" +#include "util.h" static struct shash_node *shash_find__(const struct shash *, const char *name, size_t name_len, @@ -100,6 +101,7 @@ shash_is_empty(const struct shash *shash) size_t shash_count(const struct shash *shash) { + ovs_assert(shash); return hmap_count(&shash->map); } diff --git a/lib/simap.c b/lib/simap.c index 0ee08d74d..1c01d4ebe 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -17,6 +17,7 @@ #include #include "simap.h" #include "hash.h" +#include "util.h" static size_t hash_name(const char *, size_t length); static struct simap_node *simap_find__(const struct simap *, @@ -84,6 +85,7 @@ simap_is_empty(const struct simap *simap) size_t simap_count(const struct simap *simap) { + ovs_assert(simap); return hmap_count(&simap->map); } diff --git a/lib/smap.c b/lib/smap.c index 47fb34502..122adca27 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -300,6 +300,7 @@ smap_is_empty(const struct smap *smap) size_t smap_count(const struct smap *smap) { + ovs_assert(smap); return hmap_count(&smap->map); }